Re: Sorting with DISTINCT ON - Mailing list pgsql-general

From Jorge Godoy
Subject Re: Sorting with DISTINCT ON
Date
Msg-id 878xgdwqyl.fsf@gmail.com
Whole thread Raw
In response to Sorting with DISTINCT ON  (Nico Grubert <nicogrubert@gmail.com>)
Responses Re: Sorting with DISTINCT ON  (Nico Grubert <nicogrubert@gmail.com>)
List pgsql-general
Nico Grubert <nicogrubert@gmail.com> writes:

> My first try was this SQL query:
>
>   SELECT DISTINCT ON (path) path, comment_id, created, title
>     FROM bewertungen.tblcomments
>
> This does not allow me to append "ORDER BY created" since I can only sort on
> path because of  DISTINCT ON (path).

It does allow you to sort on both columns.

   SELECT DISTINCT ON (path) path, comment_id, created, title
     FROM bewertungen.tblcomments ORDER BY path, created

Maybe you need a more complex query to get what you want (and use
max(created)...).

--
Jorge Godoy      <jgodoy@gmail.com>

pgsql-general by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: Web interface to update/change postgres data.
Next
From: "pakt sardines"
Date:
Subject: Advice needed on using postgres in commercial product