k12onos
03-20-2012, 12:42 PM
Hi guys,
I have a question about retrieving data from MySQL to create a highscore list, I hope you wouldn't mind to help me :)
Here is what my MySQL table looks like:
+-----------+----------------------------+-----------------------------+------------+
| personID | username | time_used | score |
+-----------+----------------------------+-----------------------------+------------+
| 1 | john | 10 | 30 |
| 2 | george | 20 | 29 |
| 3 | john | 50 | 29 |
| 4 | bill | 25 | 32 |
| 5 | bill | 30 | 40 |
| 6 | josh | 40 | 50 |
| 7 | bill | 50 | 26 |
| 8 | george | 60 | 48 |
+-----------+----------------------------+-----------------------------+------------+
I created a quiz and for simplicity I just let the user decide their username each time they take the test. So there will be multiple username like that in the table.
Now I have figured out how to sort it out based on score (first priority) and time_used (second priority). The problem is that the double username will all be included in the highscore list.
Is there anything I could do in the MySQL SELECT process (or other alternative perhaps?) that would let me exclude the duplicate usernames? So only the upper-most username (after sorted out using the priorities above) out of the multiple usernames will be included.
Thank you in advance, I would greatly appreciate it if you could give me some pointers about this :)
I have a question about retrieving data from MySQL to create a highscore list, I hope you wouldn't mind to help me :)
Here is what my MySQL table looks like:
+-----------+----------------------------+-----------------------------+------------+
| personID | username | time_used | score |
+-----------+----------------------------+-----------------------------+------------+
| 1 | john | 10 | 30 |
| 2 | george | 20 | 29 |
| 3 | john | 50 | 29 |
| 4 | bill | 25 | 32 |
| 5 | bill | 30 | 40 |
| 6 | josh | 40 | 50 |
| 7 | bill | 50 | 26 |
| 8 | george | 60 | 48 |
+-----------+----------------------------+-----------------------------+------------+
I created a quiz and for simplicity I just let the user decide their username each time they take the test. So there will be multiple username like that in the table.
Now I have figured out how to sort it out based on score (first priority) and time_used (second priority). The problem is that the double username will all be included in the highscore list.
Is there anything I could do in the MySQL SELECT process (or other alternative perhaps?) that would let me exclude the duplicate usernames? So only the upper-most username (after sorted out using the priorities above) out of the multiple usernames will be included.
Thank you in advance, I would greatly appreciate it if you could give me some pointers about this :)