Chevy Posted January 1, 2008 Share Posted January 1, 2008 I am trying to get the top 10 rows out of a table in MySQL. The thing is I want the top 10 rows of usernames... $stuff = mysql_query("SELECT MAX(`username`) AS `username` FROM `stuff` LIMIT 10"); while ($top = mysql_fetch_array($stuff)){ echo '<hr>'.$top['username'].'<hr>'; } So if there were 4 rows with the same username i would be above the one with rows of one username. Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/83993-solved-getting-top-10/ Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 There can only be one MAX(username) so only one row will be returned by that query. SELECT username, COUNT(*) as total FROM stuff GROUP BY username ORDER BY total DESC LIMIT 10 Quote Link to comment https://forums.phpfreaks.com/topic/83993-solved-getting-top-10/#findComment-427420 Share on other sites More sharing options...
Chevy Posted January 1, 2008 Author Share Posted January 1, 2008 Thanks a ton Quote Link to comment https://forums.phpfreaks.com/topic/83993-solved-getting-top-10/#findComment-427442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.