?
Solved

Help with SQL - Find differant Last Names by SSN

Posted on 2013-12-18
1
Medium Priority
?
368 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 60

Accepted Solution

by:
Kevin Cross earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
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 Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

840 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