From: Jackson, DeJuan <djackson@cpsgroup.com>
To: Brook Milligan <brook@trillium.NMSU.Edu>
To: pgsql-sql@postgreSQL.org
Subject: RE: [SQL] finding rows in one table not in another
Date: Fri, 12 Jun 1998 15:57:54 -0500
Message-ID: <F10BB1FAF801D111829B0060971D839F2D7ED4@cpsmail> (raw)
> I need to find the set of rows in one table that are not in another
> table. I used a query like the following:
>
> select distinct id from mytable1 where id not in (select
> distinct id from mytable2);
>
> However, this revealed no rows, even though I know of instances where
> id from mytable1 is absent from id in mytable2. Is there some other
> way to do this? Am I missing something? Is there a workaround?
>
> Cheers,
> Brook
>
try:
SELECT mytable1.id
FROM mytable1
WHERE NOT EXIST (SELECT mytable2.id
FROM mytable2
WHERE mytable1.id = mytable2.id);
-DEJ
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: djackson@cpsgroup.com, brook@trillium.NMSU.Edu
Subject: Re: [SQL] finding rows in one table not in another
In-Reply-To: <F10BB1FAF801D111829B0060971D839F2D7ED4@cpsmail>
References: <F10BB1FAF801D111829B0060971D839F2D7ED4@cpsmail>
* 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