From: | Dorin Grunberg <dorin(at)visgen(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Subselects with IN and EXISTS |
Date: | 2000-07-10 17:21:10 |
Message-ID: | 4.2.0.58.20000710120216.00ae46d0@pophost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Ed Loehr | 2000-07-10 18:08:58 | Re: SERIAL type does not generate new ID ? |
Previous Message | Jan Wieck | 2000-07-10 15:11:51 | Re: Re: [SQL] Re: [GENERAL] lztext and compression ratios... |