Re: Selecting distinct records - Mailing list pgsql-general

From Tom Lane
Subject Re: Selecting distinct records
Date
Msg-id 13765.1037906920@sss.pgh.pa.us
Whole thread Raw
In response to Re: Selecting distinct records  ("Dave [Hawk-Systems]" <dave@hawk-systems.com>)
Responses Re: Selecting distinct records  ("Dave [Hawk-Systems]" <dave@hawk-systems.com>)
List pgsql-general
"Dave [Hawk-Systems]" <dave@hawk-systems.com> writes:
>> What I am looking to do is
>> - grab every record for $user
>> - remove any records that have identical ipaddress+sessionid+refid
>> - then sort the results by date_time or something else

> this last requirement is where the problem is...

I think you need two levels of select.  To do the DISTINCT ON you must
sort by the columns to be distinct'd.  You can re-sort the result in
an outer select.  For example:

select * from
  (select distinct on (ten) * from tenk1 order by ten) ss
order by hundred;

In practice the inner select's order by will need additional sort
columns, with which you control which row gets chosen out of any set of
duplicates.

            regards, tom lane

pgsql-general by date:

Previous
From: Mike Beachy
Date:
Subject: Re: &main::execute undefined?
Next
From: "scott.marlowe"
Date:
Subject: Re: Welcom & a problem