Re: max question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "A(dot) R(dot) Van Hook" <hook(at)lake-lotawana(dot)mo(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: max question
Date: 2005-04-13 04:46:37
Message-ID: 3273.1113367597@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"A. R. Van Hook" <hook(at)lake-lotawana(dot)mo(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Greg Stark 2005-04-13 04:56:08 Re: ignore single character in SELECT query?
Previous Message Bill Lawrence 2005-04-13 03:46:00 Re: Getting the output of a function used in a where clause