Solved

Help with SQL - Find differant Last Names by SSN

Posted on 2013-12-18
1
364 Views
Last Modified: 2013-12-19
Hi.. I have data like this.  I need to find all the records that have differant Last Names by SSN

SSN              LAST
 1                 Jones
 1                 jones
 1                brown

 2                green
2                 green

3                 black
3                 white
3                 black

The result should be

SSN
1
3


thanks
0
Comment
Question by:JElster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 39727601
Do you consider the 'jones' and 'Jones' different entries?  In other words, if you had 'Green' and 'green', would 2 also show up in the results?

Anyway, you can start with something like this.
SELECT SSN
FROM your_table_name
GROUP BY SSN
HAVING COUNT(DISTINCT LAST) > 1
;

Open in new window


There are some other solutions, but this one should work.  If the answer to the question above is the rows with case differences should be treated the same, just make sure your collation is case insensitive.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

728 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