negative queries puzzle - Mailing list pgsql-sql

From Jinn Koriech
Subject negative queries puzzle
Date
Msg-id 1028142936.16285.44.camel@morph.magiclamp.2y.net
Whole thread Raw
Responses Re: negative queries puzzle  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Re: negative queries puzzle  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Re: negative queries puzzle  (Ludwig Lim <lud_nowhere_man@yahoo.com>)
List pgsql-sql
hi all,

here's a query i've never been able to improve:

i have an old data set and a new data set - in this case uk postcodes
with eastings and northings.  i want to extract the new and changed
postcodes from the new set.  to get the changed entries i use a join and
it works okay:

SELECT n.postcode, n.easting, n.northing FROM v_postcode_new n,
v_postcode_old o WHERE n.postcode = o.postcode AND (n.easting <>
o.lattitude OR n.northing <> o.longitude);


but then to get the entirely new items out i use a sub query which takes
for ever

SELECT DISTINCT * FROM v_postcode_new WHERE postcode NOT IN ( SELECT
postcode FROM v_postcode_old ) ORDER BY postcode ASC;

does anyone know of a quicker way to accomplish this?  i guess there
must be some cleaver way around it, but it's beyond me.

thanks,
jinn


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: SQL syntax
Next
From: Stephan Szabo
Date:
Subject: Re: negative queries puzzle