Re: query question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pg noob <pgnube(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: query question
Date: 2011-09-21 15:11:18
Message-ID: 23206.1316617878@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

pg noob <pgnube(at)gmail(dot)com> writes:
> Is there an efficient way to select the set of rows which have the max
> values across multiple columns?

I think SELECT DISTINCT ON might help you. The idea is to sort the rows
in an appropriate order then take the first row from each group. Look
at the "weather reports" example in PG's SELECT reference page for
inspiration.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message e-letter 2011-09-21 23:04:07 ERROR: invalid input syntax for integer:
Previous Message Shaun Thomas 2011-09-21 12:48:13 Re: PG 9 adminstrations