Subselects with IN and EXISTS - Mailing list pgsql-sql

From Dorin Grunberg
Subject Subselects with IN and EXISTS
Date
Msg-id 4.2.0.58.20000710120216.00ae46d0@pophost
Whole thread Raw
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: Type conversion
Next
From: "Tony Nakamura"
Date:
Subject: Supported Encoding