From: Oliver Elphick <olly@lfix.co.uk>
To: Thomas Metz <tmetz@gsf.de>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] SELECT DISTINCT ON ... ORDER BY ...
Date: Thu, 28 Jan 1999 14:55:27 +0000
Message-ID: <199901281455.OAA23605@linda.lfix.co.uk> (raw)
In-Reply-To: <tmetz@gsf.de> <36B05F8F.DFB94ED8@gsf.de>
Thomas Metz wrote:
>I have the following problem:
>
>Assuming the table TEST as follows:
>
>ID NAME
>-----------------
>1 Alex
>2 Oliver
>1 Thomas
>2 Fenella
...
>SELECT DISTINCT ON id, name FROM test ORDER BY name;
>produces:
>
>ID NAME
>-----------------
>1 Alex
>2 Fenella
>1 Thomas
>
>I would have expected only two rows in both queries. I don't care which
>names actually appear in the output as long as they are sorted, but
>there should no longer be duplicate id's.
I looked at the documentation for SELECT and found that DISTINCT ON is
mentioned but not explained; there are also some other parts of that
documentation that need expanding or correcting, so I'm doing that at
the moment.
Is there any intended difference between DISTINCT ON and GROUP BY? (I
realise from this thread that there is an actual difference!)
Am I correct in saying that DISTINCT ON is not part of SQL92?
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP key from public servers; key ID 32B8FAA1
========================================
"Many are the afflictions of the righteous; but the
LORD delivereth him out of them all."
Psalm 34:19
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: olly@lfix.co.uk, tmetz@gsf.de, pgsql-sql@hub.org
Subject: Re: [SQL] SELECT DISTINCT ON ... ORDER BY ...
In-Reply-To: <199901281455.OAA23605@linda.lfix.co.uk>
References: <199901281455.OAA23605@linda.lfix.co.uk>
* 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