Skip site navigation (1) Skip section navigation (2)

RE: [SQL] finding rows in one table not in another

From: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>
To: Brook Milligan <brook(at)trillium(dot)NMSU(dot)Edu>, pgsql-sql(at)postgreSQL(dot)org
Subject: RE: [SQL] finding rows in one table not in another
Date: 1998-06-12 20:57:54
Message-ID: F10BB1FAF801D111829B0060971D839F2D7ED4@cpsmail (view raw or flat)
Thread:
Lists: pgsql-sql
> 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

Responses

pgsql-sql by date

Next:From: Tim J TrowbridgeDate: 1998-06-12 21:21:27
Subject: Re: [SQL] DefineQueryRewrite: rule plan string too big
Previous:From: Brook MilliganDate: 1998-06-12 20:39:25
Subject: finding rows in one table not in another

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group