Jump to content

strugging with distinct


michaellunsford

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.