IN vs EXIIST - Mailing list pgsql-general

From Jean-Christian Imbeault
Subject IN vs EXIIST
Date
Msg-id 3D893914.5030401@mega-bucks.co.jp
Whole thread Raw
Responses Re: IN vs EXIIST  (Darren Ferguson <darren@crystalballinc.com>)
Re: IN vs EXIIST  (Bill Gribble <grib@linuxdevel.com>)
Re: IN vs EXIIST  (Jochem van Dieten <jochemd@oli.tudelft.nl>)
List pgsql-general
I find myself writing a lot of queries with this pattern:

select distinct key1 from A where id not it
   (select distinct key1 from A where x='false');

The reason being that key1 is not a primary key (key1, key2 is the
primary key). i.e. I have a table like this

key1    key2    x
------------------
a    1    t
a    2    t
a    3    f
b    1    t
b    2    t
b    3    t
c    3    t
c    4    f

So basically I want key1 values for which all the X's are true.

I've seen many posts saying that using IN is not optimal and replacing
it with EXISTS is much better. I've read the only docs but I can't
understand the difference between the two or how to convert.

Can someone point me to some other docs or explain to me how to convert?
Or is my table schema wrong?

Thanks!

Jc


pgsql-general by date:

Previous
From: "Rob Hutton"
Date:
Subject: Aliasing all fields
Next
From: Darren Ferguson
Date:
Subject: Re: IN vs EXIIST