Re: DISTINCT ordering

From: Andrew Hammond <ahammond(at)ca(dot)afilias(dot)info>
To: Ron St-Pierre <rstpierre(at)syscor(dot)com>
Cc: Jake Stride <nsuk(at)users(dot)sourceforge(dot)net>, pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: DISTINCT ordering
Date: 2004-08-10 19:53:05
Message-ID: 411927A1.4030808@ca.afilias.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Ron St-Pierre wrote:
> Jake Stride wrote:
>
>> I have a view from which I select values, but I need to do a 'SELECT
>> DISTINCT' query on a 'varchar' column and order by lower case eg:
>>
>> SELECT DISTINCT name FROM someview ORDER BY lower(name)
>>
> If this is what you want, wouldn't 'Foo' and 'foo' both show up in your
> output? If you only wanted one 'foo' you could use:
>
> SELECT DISTINCT lower(name) FROM someview ORDER BY lower(name);
>
> otherwise something like:
> SELECT lower (SS.name) FROM (SELECT DISTINCT name FROM someview) SS
> ORDER BY lower(name);
> would return 'foo' twice in the output.

Or even

SELECT DISTINCT ON (lower(name)) name
FROM someview
ORDER BY lower(name);

--
Andrew Hammond 416-673-4138 ahammond(at)ca(dot)afilias(dot)info
Database Administrator, Afilias Canada Corp.
CB83 2838 4B67 D40F D086 3568 81FC E7E5 27AF 4A9A

Attachment Content-Type Size
ahammond.vcf text/x-vcard 509 bytes

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Christian Poecher 2004-08-10 21:33:38 Re: Query result to a file
Previous Message Chris Means 2004-08-10 19:05:21 New installation of 8.0 Beta1 Failed to create process for initdb: 1385