Thread: EXISTS Keyword

EXISTS Keyword

From
Date:
Hello!

I vaguely remember that someone said somewhere that
EXISTS runs faster than IN:

SELECT * FROM table1 where field1 EXISTS (SELECT
field4 FROM table2)

However, all I got from version 7.1.3 is:

ERROR:  parser: parse error at or near "exists"

While below works:

SELECT * FROM table1 where field1 IN (SELECT field4
FROM table2)

Any key points I have missed?

CN

--------------------------------------------------------
You too can have your own email address from Eurosport.
http://www.eurosport.com







Re: EXISTS Keyword

From
Bruce Momjian
Date:
> Hello!
> 
> I vaguely remember that someone said somewhere that
> EXISTS runs faster than IN:
> 
> SELECT * FROM table1 where field1 EXISTS (SELECT
> field4 FROM table2)

Move field1 into the subquery and join it to table2.  See the FAQ for an
example.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026