X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E9FEF4753A1 for ; Sat, 1 Mar 2003 13:52:46 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 68083-02 for ; Sat, 1 Mar 2003 13:52:31 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 07F97474E61 for ; Sat, 1 Mar 2003 13:52:31 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id E8C1B43A94A; Sat, 1 Mar 2003 13:52:30 -0500 (EST) From: "Nicolas Fertig" X-Newsgroups: comp.databases.postgresql.sql Subject: OUTER JOIN with filter Date: Sat, 1 Mar 2003 19:53:27 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Lines: 43 Message-ID: <3e61011d$0$1220$5402220f@news.sunrise.ch> To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/19 X-Sequence-Number: 12059 Hello, Can anyone help me with the problem bellow ? I want to have all the row in table "table_main" with the value in the table "table_slave" (value or null if not exist) It is possible to have the same result without sub-select in OUTER JOIN (speed problem on big table) ? Actualy this is what I make... CREATE TABLE "table_main" ( "id" int4, "some_field" varchar(100) ); CREATE TABLE "table_slave" ( "id" int4, "name" varchar(100), "c1" varchar(30) ); SELECT TM.some_field, TS.name FROM table_main TM LEFT OUTER JOIN (SELECT name FROM table_slave WHERE c1 = 'myvalue') TS USING(id) the request bellow is not correct: SELECT TM.some_filed, TS.name FROM table_main TM LEFT OUTER JOIN table_slave TS USING(id) WHERE (TS.c1 = 'myc1' OR TS.c1 IS NULL) Many thanks, Nicolas