"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