Thread: Subselects with IN and EXISTS

Subselects with IN and EXISTS

From
Dorin Grunberg
Date:
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