I have a table with the following structure…
--------------------------------
id | state_abbr | poll_date
1 GA 2010-01-01
2 GA 2011-01-01
3 NC 2011-02-01
-------------------------------
I need a query that will bring back the latest poll_date for each state. I am using group by but I can’t find out how to order within that to bring back the latest poll_date. It just brings back the first poll_date for each state. So GA would be 2010-01-01 and the NC would be 2011-02-01 and the order by would then order on those values. What can I do to get around this??
How about
Since you can’t group on more than 1 thing, this way you perform the group, collect the aggregate max date and then use that data to select the final corresponding row(s).
Edit: removed DISTINCT ROW brain lapse, sorry, its what i get for being up so late. 🙂