snuff Posted November 1, 2011 Share Posted November 1, 2011 Hey all, I'm unsure of how to do this any help would be appreciated. Question: 1. how do we get the A1 where column 3 is the most recent date? Data: Column1--Column2-Column3 A1-------Dog-----2001-12 A1-------Dog-----2001-09 A1-------Dog-----2001-08 A1-------Dog-----2001-07 B1-------Dog-----2001-12 B1-------Dog-----2001-11 B1-------Dog-----2001-01 Result: Column1--Column2-Column3 A1-------Dog-----2001-12 B1-------Dog-----2001-12 Any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/250261-unique-row-based-on-date/ Share on other sites More sharing options...
mikosiko Posted November 2, 2011 Share Posted November 2, 2011 use an aggregate function http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html Quote Link to comment https://forums.phpfreaks.com/topic/250261-unique-row-based-on-date/#findComment-1284127 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2011 Share Posted November 2, 2011 If you want the specific rows - http://dev.mysql.com/doc/refman/5.5/en/example-maximum-column-group-row.html Quote Link to comment https://forums.phpfreaks.com/topic/250261-unique-row-based-on-date/#findComment-1284131 Share on other sites More sharing options...
The Little Guy Posted November 2, 2011 Share Posted November 2, 2011 You could try this: select * from table order by Column3 desc limit 2 Quote Link to comment https://forums.phpfreaks.com/topic/250261-unique-row-based-on-date/#findComment-1284275 Share on other sites More sharing options...
himmer Posted November 2, 2011 Share Posted November 2, 2011 thanks for the replies This worked: SELECT Column1, Column2, MAX(Column3) FROM data GROUP By Column1; Quote Link to comment https://forums.phpfreaks.com/topic/250261-unique-row-based-on-date/#findComment-1284349 Share on other sites More sharing options...
fenway Posted November 2, 2011 Share Posted November 2, 2011 You can't do that -- you can't select non-GROUP BY fields that aren't aggregates. Column2 is likely garbage. Quote Link to comment https://forums.phpfreaks.com/topic/250261-unique-row-based-on-date/#findComment-1284434 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.