Jump to content

Grouping Items in MySQL


SharkBait

Recommended Posts

I have the following:

[code]
SELECT *, COUNT(*) FROM users GROUP BY COUNT(*)
[/code]

Now, how can I show the results from above where COUNT(*) is greater than 1? What I am trying to do if find all the duplicate usernames (i'm trying to clean up an old database before I use it in a new project)

If I make the username field unique, it only shows me the duplicates one at a time. Quite tedious.



Link to comment
Share on other sites

[!--quoteo(post=371140:date=May 3 2006, 08:45 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 3 2006, 08:45 PM) [snapback]371140[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Sounds like you want following:

[code]SELECT username, COUNT(*) AS dups FROM users GROUP BY username HAVING dups > 1[/code]

Hope that helps.
[/quote]


Ahh thats it.

Thanks!
Link to comment
Share on other sites

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.