Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Order by count of rows
12-24-2013, 12:46 PM #1
- Join Date
- Jul 2011
- Thanked 0 Times in 0 Posts
Order by count of rows
I have database table like that:
and the data goes like that:
I want to make SQL query that will order this results by the user with the most values
if userid 1 has 6 rows included his id, and it's the highest (no more users with more than 6 rows) it will show him first.
I am using PHP.
--Thanks in advanceNeed domain? Buy Cheap Domain at Rapid Host :)
12-24-2013, 07:49 PM #2
The LIMIT can be any number you want. With LIMIT 1 you will only get the user with the most values. But CAUTION: What if you have 3 users all with the same top number of values??Code:SELECT userid, COUNT(value) AS howmany GROUP BY userid ORDER BY howmany DESC LIMIT 1
Be yourself. No one else is as qualified.