Solved

Fine records with duplicate ssn and date of birth but different record ids

Posted on 2009-04-13
5
314 Views
Last Modified: 2012-05-06
I am stuck on this query which seems like it should be simple.
I have a table that has five columns:
member_id (PK)
last_name
first_name
social_security_no
birthdate

I am trying to find all records where a single person (same social_security_no and birthdate) has one or more different member_ids.
Any assistance is appreciated. Thanks.
0
Comment
Question by:c4e41961
5 Comments
 
LVL 22

Accepted Solution

by:
dportas earned 150 total points
ID: 24133153
SELECT *
FROM tbl t
WHERE EXISTS
 (SELECT 1
  FROM tbl
  WHERE social_security_no = t.social_security_no
   AND birthdate = t.birthdate
   AND member_id <> t.member_id);
0
 
LVL 1

Assisted Solution

by:joshbenner
joshbenner earned 50 total points
ID: 24133160
Something like this:
SELECT
  *,
  COUNT(*)
FROM myTable
GROUP BY social_security_no, birthdate
ORDER BY COUNT(*) DESC

Open in new window

0
 
LVL 1

Expert Comment

by:joshbenner
ID: 24133162
You could add a HAVING COUNT(*) > 1
0
 
LVL 15

Assisted Solution

by:MNelson831
MNelson831 earned 50 total points
ID: 24133174
Select * from MyTable where SSN in (

Select SSN from MyTable having Count(*) >1 group by SSN)
0
 

Author Closing Comment

by:c4e41961
ID: 31569689
Thanks!  I appreciate your solutions!
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

772 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