|
Question : Using SQL to find non-duplicate data.
|
|
I know that sounds strange, but let me explain.
Lets say I have a database Table that contains information on accounts. Each account is assosciated with a SSN and a user can have more than one account. I am trying to find all the users who do NOT have more than ONE account. I only want the users who have one account and one accound only. If the user has more than one account then I do not want that users information to be returned by my SQL query.
This may sound like a strange request but this is part of a much bigger picture. I can handle the rest of my problem if someone could possible help me perform what is mentioned above. The Database I am working with was set up by your typical, non-Database Administrator kind of person and thus I have to go about this problem is a rather unusual way.
I thought about using the SELECT DISTINCT Command but If I'm not mistaking that will avoid returning duplicates but will still return accounts that do contain duplicate values.
Anyways, if anyone has any suggestions then please let me know.
Thanks.
|
|
Answer : Using SQL to find non-duplicate data.
|
|
Select * from MyTable where SSN In (
Select SSN From MyTable Group By SSN Having Count(SSN) = 1 )
|
|
|
|