Panjabel Posted August 17, 2007 Share Posted August 17, 2007 Hello i have table members with many users and comments i want to select unique users and order them by number of comments select distinct(userid) from members order by count(comments) desc the command will display the same users many times, not unique users. what's wrong in the query ? Quote Link to comment https://forums.phpfreaks.com/topic/65339-solved-select-distinct-count-problem/ Share on other sites More sharing options...
jlp09550 Posted August 17, 2007 Share Posted August 17, 2007 So, you just want to show the different usernames like this: Username1 Username2 Username3 .. instead of: Username1 Username1 Username2 Username3 Username3? If so, try (not sure if it would work, but you can try): select distinct(userid) from members order by count(comments) group by userid desc Quote Link to comment https://forums.phpfreaks.com/topic/65339-solved-select-distinct-count-problem/#findComment-326294 Share on other sites More sharing options...
Panjabel Posted August 17, 2007 Author Share Posted August 17, 2007 doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/65339-solved-select-distinct-count-problem/#findComment-326296 Share on other sites More sharing options...
jlp09550 Posted August 17, 2007 Share Posted August 17, 2007 doesn't work Hmm. Well, for my users online script, I had to group the usernames because they would show up more than once if someone has a [very] dynamic IP, like AOL. The query I used: SELECT `username` FROM `users_online` GROUP BY `username` ORDER BY `lastvisit` DESC Might help a bit if you would understand that. But it does indeed work on this side. Quote Link to comment https://forums.phpfreaks.com/topic/65339-solved-select-distinct-count-problem/#findComment-326320 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.