pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
To: The Hermit Hacker <scrappy@hub.org>
To: pgsql-sql@postgresql.org
Subject: Re: DELETE FROM tableA WHERE NOT IN tableB ...
Date: Tue, 18 Apr 2000 15:00:48 +0100
Message-ID: <006701bfa93e$801f61b0$760e01a3@oucs.ox.ac.uk> (raw)
References: <Pine.BSF.4.21.0004181015390.226-100000@thelab.hub.org>

----- Original Message -----
From: "The Hermit Hacker" <scrappy@hub.org>
To: <pgsql-sql@postgresql.org>
Sent: Tuesday, April 18, 2000 2:23 PM
Subject: [SQL] DELETE FROM tableA WHERE NOT IN tableB ...


>
> And now for todays trick question ...
>
> have two tables, one of them is simple a string and a serial value, the
> second one is the serial value and more data ...
>
> I want to clean out all records from tableB older then date (that is
> easy), then I want to clean out all values from tableB where there is no
> corresponding record in tableB ...
>
> basically tableA's serial field is unique, but tableB's could have
> multiple records associated with.
>
> basically, what i've tried to do in a SELECT is something like:
>
> SELECT referer_id
>   FROM referer_data
> EXCEPT
>       SELECT distinct(referer_id) FROM referer_link;

Not quite sure if I've understood your setup (you've got one too many
TableB's in the descrn, I think!)
but what about

 DELETE FROM referer_data WHERE NOT EXISTS (SELECT referer_id FROM
referer_link) WHERE referer_link.referer_id=referer_data.referer_id);

or swop the referer_links and referer_datas.




view thread (4+ messages)  latest in thread

Message-ID: <006701bfa93e$801f61b0$760e01a3@oucs.ox.ac.uk>
Permalink:  ../006701bfa93e$801f61b0$760e01a3@oucs.ox.ac.uk/
Also on:    postgresql.org/message-id/006701bfa93e$801f61b0$760e01a3@oucs.ox.ac.uk

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: moray.mcconnachie@computing-services.oxford.ac.uk, scrappy@hub.org
  Subject: Re: DELETE FROM tableA WHERE NOT IN tableB ...
  In-Reply-To: <006701bfa93e$801f61b0$760e01a3@oucs.ox.ac.uk>
  References: <Pine.BSF.4.21.0004181015390.226-100000@thelab.hub.org> <006701bfa93e$801f61b0$760e01a3@oucs.ox.ac.uk>

* 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