X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 817FA32A8A3 for ; Fri, 8 Oct 2004 16:07:07 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53968-01 for ; Fri, 8 Oct 2004 15:07:02 +0000 (GMT) Received: from window.monsterlabs.com (window.monsterlabs.com [216.183.105.176]) by svr1.postgresql.org (Postfix) with SMTP id E4E4532A9BE for ; Fri, 8 Oct 2004 16:07:00 +0100 (BST) Received: (qmail 16744 invoked from network); 8 Oct 2004 15:06:59 -0000 Received: from pcp03902917pcs.nash01.tn.comcast.net (HELO ?192.168.0.114?) (68.53.109.160) by 0 with SMTP; 8 Oct 2004 15:06:59 -0000 In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v619) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit Cc: sad@bankir.ru, pgsql-sql@postgresql.org, mmurrain@dbdes.com From: Thomas F.O'Connell Subject: Re: help on a query Date: Fri, 8 Oct 2004 10:06:57 -0500 To: "CHRIS HOOVER" X-Mailer: Apple Mail (2.619) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/50 X-Sequence-Number: 19153 I think the OUTER JOIN version is probably more efficient, but EXPLAIN would tell you. -tfo On Oct 8, 2004, at 8:02 AM, CHRIS HOOVER wrote: > Just curious, what is wrong with the first way of coding the solution? > ------------------( Forwarded letter 1 follows )--------------------- > Date: Fri, 8 Oct 2004 08:44:23 +0400 > To: Thomas.F.O'Connell[tfo]@sitening.com.comp, mmurrain@dbdes.com.comp > Cc: pgsql-sql@postgresql.org.comp > From: sad@bankir.ru.comp > Sender: pgsql-sql-owner+m19150@postgresql.org.comp > Subject: Re: [SQL] help on a query > > On Friday 08 October 2004 07:10, Thomas F.O'Connell wrote: >> A query that should get the job done is: >> >> SELECT registration_id >> FROM registrations r >> WHERE NOT EXISTS ( >> SELECT 1 >> FROM receipts >> WHERE registration_id = r.registration_id >> ); > > Don't, PLEASE, don't !!! > > drive this way : > > SELECT r.registration_id > FROM registrations AS r > LEFT OUTER JOIN receipts AS rec > ON rec.registration_id = r.registration_id > WHERE rec.registration_id IS NULL;