I am trying to create a mysql query to retrieve a row for each city using the latest trans_date and trans_count. I want to return only one row for each city.
Table operations
------------------
id = integer
trans_date = date
trans_city = varchar
trans_count = integer
Data examples
--------------
id trans_date trans_city trans_count
-- ---------- ---------- -----------
1 2011-01-10 seattle 2104
2 2011-04-15 seattle 2072
3 2011-05-30 seattle 2057
4 2010-04-27 houston 5622
5 2010-04-30 houston 241
6 2010-05-25 houston 261
Required query results (one row for a city with the most recent date and quantity for that city)
---------------------
id trans_date trans_city trans_count
-- ---------- ---------- -----------
3 2011-05-30 seattle 2057
6 2010-05-25 houston 261
None of the samples I found returns this result set that I am looking for. Any help was appreciated.
Thank,
-Scott
source
share