Received: from morph.magiclamp.2y.net (81-86-159-111.dsl.pipex.com [81.86.159.111]) by postgresql.org (Postfix) with ESMTP id ABA77475D9C for ; Wed, 31 Jul 2002 15:15:37 -0400 (EDT) Received: (from jinn@localhost) by morph.magiclamp.2y.net (8.11.6/8.11.6) id g6VJFbM23348; Wed, 31 Jul 2002 20:15:37 +0100 Subject: negative queries puzzle From: Jinn Koriech To: PostgreSQL Mailing List Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 31 Jul 2002 20:15:36 +0100 Message-Id: <1028142936.16285.44.camel@morph.magiclamp.2y.net> Mime-Version: 1.0 X-Archive-Number: 200207/460 X-Sequence-Number: 8838 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