Re: max question - Mailing list pgsql-sql

From Tom Lane
Subject Re: max question
Date
Msg-id 3273.1113367597@sss.pgh.pa.us
Whole thread Raw
In response to max question  ("A. R. Van Hook" <hook@lake-lotawana.mo.us>)
List pgsql-sql
"A. R. Van Hook" <hook@lake-lotawana.mo.us> writes:
> I am trying to pull rows that have the max. contdate. Why does the 
> following give more than 2 rows?
>  ql "select oid,* from ccontinue where citkey ='04-0594703' group by 
> oid,citkey,contby,contdate,abcontinue,ccdate having max(contdate) = 
> contdate"

HAVING is going to interpret the max() aggregate separately for each
group ... that is, the above query asks for all the rows that have the
largest contdate within their group.  Given that OID is one of the
grouping columns, I'd pretty much expect that to select every single
row in the table, because each row will form its own unique group :-(

What is it you are trying to accomplish here?  In particular, what
led to that choice of GROUP BY?
        regards, tom lane


pgsql-sql by date:

Previous
From: "Bill Lawrence"
Date:
Subject: Re: Getting the output of a function used in a where clause
Next
From: Greg Stark
Date:
Subject: Re: ignore single character in SELECT query?