dimanche 4 janvier 2015

Sorting Data With Distinct in Sqlite

I created a game and I want to store user's high scores.


For example, I have a table named scores with these records...



ID | Name | Score
1 | Grace | 90
2 | Grace | 100
3 | Ben | 70
4 | Kim | 80
5 | Grace | 74
6 | Grace | 50
7 | Ben | 80
8 | Honey | 23
9 | Babe | 85
10 | Ben | 120


I want to display the names of player (without duplicates) and sorted it from highest to lowest score.


I tried this...



SELECT DISTINCT Name FROM scores ORDER BY Score DESC


But it doesn't work for all times. It gives me this output...



Grace
Babe
Kim
Ben
Honey


From the table, Ben has the highest score. From this output, Grace is the first one listed but she did not get the highest score.


What Sqlite code should I put so that it can display these expected output?



Ben
Grace
Babe
Kim
Honey

Aucun commentaire:

Enregistrer un commentaire