Received: from mail.visgen.com (uu-t1-6.visgen.com [216.94.71.6]) by hub.org (8.10.1/8.10.1) with ESMTP id e6AGP3W02250 for ; Mon, 10 Jul 2000 12:25:03 -0400 (EDT) Received: from dorin (bay-auto-121 [10.1.18.121]) by mail.visgen.com (8.9.3/8.9.3) with ESMTP id MAA27195 for ; Mon, 10 Jul 2000 12:25:01 -0400 (EDT) Message-Id: <4.2.0.58.20000710120216.00ae46d0@pophost> X-Sender: dorin@pophost X-Mailer: QUALCOMM Windows Eudora Pro Version 4.2.0.58 Date: Mon, 10 Jul 2000 12:21:10 -0500 To: pgsql-sql@postgresql.org From: Dorin Grunberg Subject: Subselects with IN and EXISTS Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200007/99 Hello, Here is my query. SELECT id, title, type, sub_type, order_number, version, date, referred_to, referred_in FROM sop WHERE (type||sub_type||order_number, version) IN ^^^ (SELECT type||sub_type||order_number, max(version) FROM sop GROUP BY type||sub_type||order_number) ORDER BY type, sub_type, order_number It looks like is not as fast as I would like so I thought of rewriting it as: SELECT id, title, type, sub_type, order_number, version, date, referred_to, referred_in FROM sop WHERE EXISTS (SELECT type||sub_type||order_number, max(version) FROM sop GROUP BY type||sub_type||order_number) ORDER BY type, sub_type, order_number The results that I get are not the same. Could anyone point what am I doing wrong? tia Dorin