pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jinn Koriech <lists@idealint.co.uk>
To: PostgreSQL Mailing List <pgsql-sql@postgresql.org>
Subject: negative queries puzzle
Date: 31 Jul 2002 20:15:36 +0100
Message-ID: <1028142936.16285.44.camel@morph.magiclamp.2y.net> (raw)

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



view thread (5+ messages)  latest in thread

Message-ID: <1028142936.16285.44.camel@morph.magiclamp.2y.net>
Permalink:  ../1028142936.16285.44.camel@morph.magiclamp.2y.net/
Also on:    postgresql.org/message-id/1028142936.16285.44.camel@morph.magiclamp.2y.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: lists@idealint.co.uk
  Subject: Re: negative queries puzzle
  In-Reply-To: <1028142936.16285.44.camel@morph.magiclamp.2y.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox