Re: Single Table Select With Aggregate Function

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Single Table Select With Aggregate Function
Date: 2012-01-04 00:06:21
Message-ID: alpine.LNX.2.00.1201031605390.18032@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 3 Jan 2012, Tom Lane wrote:

> You can do that type of thing using subqueries, eg
>
> select ... from mytab
> where col = (select max(col) from mytab where ...)

Thanks, Tom. That's what I thought I needed.

> or if you don't mind a nonstandard construct, consider SELECT DISTINCT ON.
> There's an example of how to use that in the SELECT reference page
> (look for the weather-reports example). In any case you're going to
> have to consider what you want to have happen when there are multiple
> occurrences of the maximum value.

I'll look at that, too.

Much appreciated,

Rich

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2012-01-04 00:07:26 Re: Single Table Select With Aggregate Function
Previous Message David Johnston 2012-01-04 00:00:46 Re: Single Table Select With Aggregate Function