Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8QEY4h92835 for ; Wed, 26 Sep 2001 10:34:04 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f8QEOgg11829 for pgsql-sql@postgresql.org; Wed, 26 Sep 2001 10:24:42 -0400 (EDT) (envelope-from news) From: anssiman@my-deja.com (A. Mannisto) X-Newsgroups: comp.databases.postgresql.sql Subject: Subquery with IN or EXISTS Date: 26 Sep 2001 07:24:41 -0700 Organization: http://groups.google.com/ Lines: 20 Message-ID: <8b9752ea.0109260624.5b0d2c20@posting.google.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com To: pgsql-sql@postgresql.org X-Archive-Number: 200109/242 X-Sequence-Number: 4924 Hello, does anybody know why this: SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2) equals this: SELECT * FROM tab WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2) but this: SELECT * FROM tab WHERE col1 IN (SELECT col2 FROM TAB2 WHERE col3='huu') equals _NOT_ this: SELECT * FROM tab WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2 AND col3='huu') E.g. resultset is not the same in last two statements. Can I get same set as IN statement somehow using EXISTS (performance issue)?