Received: from frithjof.reiner (qmailr@c59.dialin.tuwien.ac.at [192.35.243.69]) by hub.org (8.9.3/8.9.3) with SMTP id QAA32275 for ; Fri, 24 Sep 1999 16:52:19 -0400 (EDT) (envelope-from areiner@tph.tuwien.ac.at) Received: (qmail 304 invoked by uid 500); 24 Sep 1999 20:47:49 -0000 From: "Albert REINER" Date: Fri, 24 Sep 1999 22:47:49 +0200 To: "'pgsql-sql@hub.org'" Subject: Re: [SQL] comparing 2 tables. . . Message-ID: <19990924224748.A182@frithjof> Mail-Followup-To: "'pgsql-sql@hub.org'" References: <01BF06A4.7FFF3C60@Dan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.6i In-Reply-To: ; from Stuart Rison on Fri, Sep 24, 1999 at 03:32:51PM +0100 On Fri, Sep 24, 1999 at 03:32:51PM +0100, Stuart Rison wrote: ... > Try: > > SELECT tab1.pkey FROM tab1 WHERE tab1.pkey NOT IN (SELECT > tab2.pkey FROM tab2.pkey); > > or else (faster): > > SELECT tab1.pkey FROM tab1 WHERE NOT EXISTS (SELECT 1 FROM > tab2 WHERE tab1.pkey=tab2.pkey); Maybe this is trivial, but... Is there a simple way to see that/why the last query is faster? Albert. -- --------------------------------------------------------------------------- Post an / Mail to / Skribu al: Albert Reiner ---------------------------------------------------------------------------