Solved

Help with SQL - Find differant Last Names by SSN

Posted on 2013-12-18
1
358 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
1 Comment
 
LVL 59

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

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…
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

15 Experts available now in Live!

Get 1:1 Help Now