Hi,
I need to retrieve only 1 row for each 'message_id', with the Latest Date('sent_date'):
-------------------------------------
message_id | sent_date |
-------------------------------------
805 | 2010-08-04 17:48:24 | <---
805 | 2010-08-03 17:48:24 |
1007 | 2010-08-07 17:48:24 |
1007 | 2010-08-09 17:48:24 | <---
1007 | 2010-08-08 17:48:24 |
-------------------------------------
The Results should be:
-------------------------------------
message_id | sent_date |
-------------------------------------
805 | 2010-08-04 17:48:24 |
1007 | 2010-08-09 17:48:24 |
-------------------------------------
I have tried the following query which only retrieves the latest date, and not the latest date for each 'message_id'..
$sql = "SELECT DISTINCT message_id, max(date_sent)
FROM mail";
also tried:
$sql = "SELECT DISTINCT message_id, date_sent
FROM mail
HAVING date_sent = max(date_sent)";
Please help