Re: filter duplicates by priority - Mailing list pgsql-general

From Sam Mason
Subject Re: filter duplicates by priority
Date
Msg-id 20090714162413.GB5407@samason.me.uk
Whole thread Raw
In response to filter duplicates by priority  ("Clark Slater" <pg@slatech.com>)
List 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/

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: filter duplicates by priority
Next
From: "V S P"
Date:
Subject: Re: [Q] single image Table across multiple PG servers