GROUP BY and ORDER BY
Posted: Sat Jul 31, 2004 11:29 pm
I've got a table similar to:
id | name
1 name1
2 name2
3 name5
4 name5
5 name3
6 name1
7 name1
And what I'm trying to do is gruop by the name but order by the id descending. But it is using the first occurence of the id to order by, and i want it to use the last occurence.
my query : SELECT * FROM visitors GROUP BY name ORDER BY id DESC
How can i get it to sort in descending order by the id on the last occurence of the id??
If that makes any sense...
id | name
1 name1
2 name2
3 name5
4 name5
5 name3
6 name1
7 name1
And what I'm trying to do is gruop by the name but order by the id descending. But it is using the first occurence of the id to order by, and i want it to use the last occurence.
my query : SELECT * FROM visitors GROUP BY name ORDER BY id DESC
How can i get it to sort in descending order by the id on the last occurence of the id??
If that makes any sense...