Re: Unique - first - Mailing list pgsql-general

From Marcin Mańk
Subject Re: Unique - first
Date
Msg-id CAK61fk7b09NMdupaT1KYy+WdDJBqGVT6CH+=5JuKjfkFp+7nxg@mail.gmail.com
Whole thread Raw
In response to Unique - first  (Robert James <srobertjames@gmail.com>)
List pgsql-general

On Sun, Oct 27, 2013 at 2:04 PM, Robert James <srobertjames@gmail.com> wrote:
I have a table (x,y,z) - I'd like to take the rows with unique x
values - but, when more than one row have the same x value, I want the
one with the minimal z value.

You can use distinct on (which is a Postgresql extension to the SQL standard):

select distinct on(x) x, y, z
from the_table
order by x, z
Regards
Marcin Mańk

pgsql-general by date:

Previous
From: Jayadevan M
Date:
Subject: Re: search_path and current_schema
Next
From: anatoly techtonik
Date:
Subject: Re: PGAdmin and user privileges - what I do wrong?