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
287 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now