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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

17 Experts available now in Live!

Get 1:1 Help Now