I will present my table structures first (only relevant fields will be mentioned)
/* The table Users */
user_id | user_name | user_registration_date
1 | USER1 | 19/09/2010
2 | USER2 | 20/09/2010
/* The table Levels_Completed */
user_id | level_id
1 | 1
1 | 2
2 | 1
I would like to display a scoreboard. The first user on the list, will be the one with the highest count of levels he completed.
For the example above, USER1 will be displayed above USER2.
I want to receive the next data:
user_id, user_name, user_registration_date, COUNT(level_id rows) AS score
Ordered by the count of score, for each SQL row I receive.
Example:
1 | USER1 | 19/09/2010 | 2
2 | USER2 | 20/09/2010 | 1
I know how to use INNER JOIN, but I think the counting and ordering are above my current level. Help please?
1 Answer