Received: from eba-haus.de ([149.228.241.86]) by hub.org (8.9.3/8.9.3) with SMTP id DAA82871 for ; Thu, 20 Apr 2000 03:13:23 -0400 (EDT) (envelope-from DieringG@eba-haus.de) Received: from kopo001 by eba-haus.de;Thu, 20 Apr 2000 07:06:11 GMT with Novell_GroupWise; Thu, 20 Apr 2000 09:06:11 +0200 Message-Id: X-Mailer: Novell GroupWise 5.5 Date: Thu, 20 Apr 2000 09:05:44 +0200 From: "Gerhard Dieringer" To: , Subject: Antw: Problems with joining two tables Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Disposition: inline Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id DAA82908 X-Archive-Number: 200004/216 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 UNION ALL SELECT name, NULL FROM customer WHERE customer.customer_id NOT IN (SELECT customer_id FROM salesorder) ORDER BY name I hope this will help you. Gerhard