Skip site navigation (1) Skip section navigation (2)

Antw: Problems with joining two tables

From: "Gerhard Dieringer" <DieringG(at)eba-haus(dot)de>
To: <pgsql-sql(at)postgresql(dot)org>, <Michael(dot)Rudolph(at)telekom(dot)de>
Subject: Antw: Problems with joining two tables
Date: 2000-04-20 07:05:44
Message-ID: s8fec883.010@kopo001 (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Michael Rudolph wrote:

> I have two tables, the first one has one column as a reference to the index of the second. Not every row in the first table has a reference to the second table. > I now want to make a query to get all information of the first table and, if there is a reference, the corresponding information of the second table in that row. In > another programming language I would just make an if-clause but how can I do this in SQL?

What you need is an outer join but as PostgreSQL doesn't support outer joins now (7.0.0), you can simulate it with a union as explained in Bruce Momjian book:

SELECT name, order_id
FROM customer, salesorder
WHERE customer.customer_id = salesorder.customer_id
FROM customer
WHERE customer.customer_id NOT IN (SELECT customer_id FROM salesorder)

I hope this will help you.


pgsql-sql by date

Next:From: zoltan.sebestyenDate: 2000-04-20 08:03:11
Subject: RE: Check this
Previous:From: Tom LaneDate: 2000-04-20 05:45:30
Subject: Re: TOAST (was: BLOB)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group