[thelist] SQL Query : using Group By and Order By together

rudy r937 at interlog.com
Fri Jan 4 22:51:04 CST 2002


>select aplogo, aptime, min(apdate)
>      from table
>       group by aplogo
>       order by aptime DESC
>

this is still not quite right

min(apdate) is an aggregate function, and will select the lowest apdate in
each group

there is one group for each aplogo, and you will get one row for each group

but the select list also contains aptime, so the select list is not the
same as the group by list -- and this would be a syntax error in any
database except mysql

you need to decide *which* time you want from the group of dates and times
for each aplogo

in fact, why do you want a time at all with the lowest date?  do you want
the lowest time of the lowest date?  that's quite a bit more complex

why not make up a sample set of data like i did and then show the results
you want


rudy






More information about the thelist mailing list