Remove duplicate rows

From: Jiří Němec <konference(at)menea(dot)cz>
To: pgsql-general(at)postgresql(dot)org
Subject: Remove duplicate rows
Date: 2007-01-11 17:51:57
Message-ID: 476854341.20070111185157@menea.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I need to remove duplicates rows from a subquery but order these
results by a column what is not selected. There are logically two
solutions but no works.

SELECT DISTINCT sub.foo FROM (SELECT ...) AS sub ORDER BY sub.bar
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

SELECT sub.foo FROM (SELECT ...) AS sub GROUP BY sub.foo ORDER BY sub.bar
ERROR: column "sub.bar" must appear in the GROUP BY clause or be used
in an aggregate function

Does anybody know how to remove duplicate rows from a subquery and order
these results by a column what is not selected but exists in a subquery?

Thanks for any advice,

J.N.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-01-11 18:06:09 Re: Checkpoint request failed on version 8.2.1.
Previous Message NM 2007-01-11 17:49:07 storing SMALL large objects to postgres with C# (.NET ODBC layer)