We help IT Professionals succeed at work.
Get Started

T-SQL How To: Compare and List Duplicate Entries in a Table

Last Modified: 2012-05-09
SQL Server 2000.  Single table has a list of users that includes a unique user ID and a non-unique user name.

I want to search the table and list out any users that share the same non-unique user name.  For example, my table looks like this:

ID   User Name   Name
==   =========   ====
0    parker      Peter Parker
1    parker      Mary Jane Parker      
2    heroman     Joseph (Joey) Carter Jones
3    thehulk     Bruce Banner

What I want to do is do a SELECT and have the result set be:

ID   User Name   Name
==   =========   ====
0    parker      Peter Parker
1    parker      Mary Jane Parker      

from my table.

I'm not a T-SQL guru.  I can do the basic joins and such, but I'm thinking there must be an elegant way of doing this.  Barring elegance, there must be ANY way of doing this.

I appreciate any methods that you can help me with on this topic.  Thanks!
Watch Question
SQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2019
This problem has been solved!
Unlock 3 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE