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 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 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 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 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; 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. 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
Archived
This topic is now archived and is closed to further replies.