Jump to content

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/65339-solved-select-distinct-count-problem/
Share on other sites

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.