Re: Sorting with DISTINCT ON

From: Jorge Godoy <jgodoy(at)gmail(dot)com>
To: Nico Grubert <nicogrubert(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Sorting with DISTINCT ON
Date: 2007-01-08 14:09:06
Message-ID: 878xgdwqyl.fsf@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nico Grubert <nicogrubert(at)gmail(dot)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(at)gmail(dot)com>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jerry Sievers 2007-01-08 14:15:59 Re: TRIGGER BEFORE INSERT
Previous Message Devrim GUNDUZ 2007-01-08 13:43:28 Re: Web interface to update/change postgres data.