Possible Duplicate:
MySQL ORDER BY total rows of user in another table
I have 5 users (on table users):
User ID (uid) | User Name (uname)
-----------------------------------
1 Fallon
2 Jeremy
3 Matt
4 Peter
5 John
- Fallon (uid 1) has logged in 35 times so far.
- Jeremy logged in 32 times.
- Matt logged in 57 times.
- Peter logged in 43 times.
- John logged in 23 times.
Log details are stored in another table (logs):
Log ID (logid) - User ID (uid)
Now I want to represent a list of users in order of most logged times. The user who logged in the most will be at the top, second most logged user will be the second. Like:
- Matt logged in 57 times.
- Peter logged in 43 times.
- Fallon logged in 35 times.
- Jeremy logged in 32 times.
- John logged in 23 times.
Because Logs are stored in one table and User details in another. How can I, What queries should I, use to make a list like the above. Please help.
It’s just a simple query involving a
JOIN: