Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

How would write a query against a MySql db that returns all userName records greater than one record?

How would write a query against a MySql db that returns all userName records greater than one record?  I'm looking for duplicate records in the table.

I'm looking for any duplicated usernames in the table not just a single.

Thanks!

SELECT * FROM  members WHERE UserName  count < 1
0
bmanmike39
Asked:
bmanmike39
1 Solution
 
PortletPaulCommented:
OK, looking for "duplicates" will depend on what you consider to be a duplicate :)

But one very common technique is to use GROUP BY, HAVING and COUNT() like this:

select
    member_name
from members
GROUP BY
    member_name
HAVING
   COUNT(*) > 1
;

So, for the fields you want to check as a unique record (in bold) list those in BOTH the select and group by clauses
This is important! both must be the same.
0
 
bmanmike39Author Commented:
Excellent !  worked thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now