Re: filter duplicates by priority

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: filter duplicates by priority
Date: 2009-07-14 16:24:13
Message-ID: 20090714162413.GB5407@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 14, 2009 at 10:04:12AM -0400, Clark Slater wrote:
> SELECT DISTINCT ON (part_number) * FROM (
> SELECT part_number, priority FROM ...
> UNION ALL
> SELECT part_number, priority FROM ...
> UNION ALL
> SELECT part_number, priority FROM ...
> ) AS filter_duplicates ORDER BY priority,part_number
>
> The above statement does not work because if I ORDER BY
> priority,part_number then I have to DISTINCT ON (priority,part_number).
> But DISTINCT ON (priority, part_number) does not remove the repeated rows
> because the same part_number with a different priority becomes a distinct
> tuple.

I think you just want to swap the ORDER BY columns around; i.e:

ORDER BY part_number, priority

--
Sam http://samason.me.uk/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message V S P 2009-07-14 18:38:27 Re: [Q] single image Table across multiple PG servers
Previous Message Martijn van Oosterhout 2009-07-14 15:56:30 Re: filter duplicates by priority