Solved

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

Posted on 2014-10-15
2
289 Views
Last Modified: 2014-10-15
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
Comment
Question by:bmanmike39
2 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40383425
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
 

Author Closing Comment

by:bmanmike39
ID: 40383520
Excellent !  worked thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question