pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dorin Grunberg <dorin@visgen.com>
To: pgsql-sql@postgresql.org
Subject: Subselects with IN and EXISTS
Date: Mon, 10 Jul 2000 12:21:10 -0500
Message-ID: <4.2.0.58.20000710120216.00ae46d0@pophost> (raw)

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



Message-ID: <4.2.0.58.20000710120216.00ae46d0@pophost>
Permalink:  ../4.2.0.58.20000710120216.00ae46d0@pophost/
Also on:    postgresql.org/message-id/4.2.0.58.20000710120216.00ae46d0@pophost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: dorin@visgen.com
  Subject: Re: Subselects with IN and EXISTS
  In-Reply-To: <4.2.0.58.20000710120216.00ae46d0@pophost>
  References: <4.2.0.58.20000710120216.00ae46d0@pophost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox