Possible Duplicate:
SQL ORDER BY total within GROUP BY
SELECT *
FROM users_pm_in
WHERE uID = '1'
GROUP BY dialog_id
ORDER BY date DESC
Wont work properly. What i want to do is group in to dialog_id.. Then all with the dialog_id sort them by date, and then sort them by date for all..
So:
id | uID | bID | msg | dialog_id | date
--------------------------------------------------
1 | 1 | 2 | Hello | 1 | 1289158631
2 | 2 | 1 | Hi? | 1 | 1289158691
3 | 1 | 2 | Wazzaa? | 1 | 1289158931
The two entry´s of the dialog_id gets 1 (With GROUP BY). OK. And then it should order by the one of the two entrys(inside the group) that have the newest date(order by date desc). Which this case is the one with date 1289158931.
How can this be done?
UPDATE:
What i want to come out:
while($row = mysql_fetch_array($query)){
echo $row["msg"] // it should echo "Wazzaa?"
echo $row["id"] // it should give me id 3
}
It give me the last for each dialog_id, thats why i want it grouped in.
Use:
…or: