michaellunsford Posted May 19, 2011 Share Posted May 19, 2011 I'm trying to pull a list of projects in the order that they were last updated. There are a few tables, but I thought to just query the updates table so I can sort by the last updated item. I thought it was pretty simple stuff, but I just can't seem to get the query right. Any help or insights would be grand. Here's what I've tried so far: //This works great except that there are multiple updates per project - so I get loads of duplicates. "SELECT `project`,`date` FROM `table` ORDER BY `date` DESC" //This returns exactly what the previous query does "SELECT DISTINCT(`project`), `date` FROM `table` ORDER BY `date` DESC" //This returns rows with the wrong date (not sorting by date before grouping), and thereby is in the wrong order "SELECT `project`,`date` FROM `table` GROUP BY `project` ORDER BY `date` DESC" //This one says "you have an error in your mysql syntax" "SELECT `project`,`date` FROM `table` ORDER BY `date` DESC GROUP BY `project`" Link to comment https://forums.phpfreaks.com/topic/236814-strugging-with-distinct/ Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 check this link out here, should help Link to comment https://forums.phpfreaks.com/topic/236814-strugging-with-distinct/#findComment-1217719 Share on other sites More sharing options...
michaellunsford Posted May 19, 2011 Author Share Posted May 19, 2011 ahh, the optimal function is MAX(`timestamp`). The rest of that guy's solution is a little weird, but MAX() works great. Thanks for the reply. Link to comment https://forums.phpfreaks.com/topic/236814-strugging-with-distinct/#findComment-1217734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.