Jump to content

Archived

This topic is now archived and is closed to further replies.

SharkBait

Grouping Items in MySQL

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.



Share this post


Link to post
Share on other sites
Sounds like you want following:

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

Hope that helps.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

×

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.