SharkBait Posted May 3, 2006 Share Posted May 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8989-grouping-items-in-mysql/ Share on other sites More sharing options...
fenway Posted May 4, 2006 Share Posted May 4, 2006 Sounds like you want following:[code]SELECT username, COUNT(*) AS dups FROM users GROUP BY username HAVING dups > 1[/code]Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/8989-grouping-items-in-mysql/#findComment-33191 Share on other sites More sharing options...
SharkBait Posted May 4, 2006 Author Share Posted May 4, 2006 [!--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! Quote Link to comment https://forums.phpfreaks.com/topic/8989-grouping-items-in-mysql/#findComment-33316 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.