Solved

Help with SQL - Find differant Last Names by SSN

Posted on 2013-12-18
1
359 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MessageHandler Database in SQL way too large 4 40
Query - which index being used? 2 47
Following an example - removing duplicate strings 4 48
sql query help 2 44
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

22 Experts available now in Live!

Get 1:1 Help Now