SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Finding multiple records for individuals
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

JohnConklin
Starting Member

USA
2 Posts

Posted - 02/04/2014 :  15:48:49  Show Profile  Reply with Quote
I am trying to find members in one table that have different primary key values. We have data that has multiple records for individuals in the table but their have different id's associated with them. How would I query the table to find all those individuals with multiple records but different primary key values?

Thanks,
~John

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 02/04/2014 :  16:46:01  Show Profile  Reply with Quote
something like this? your [memberName] can be whatever column(s) that make up a "member".

select memberName, count(*) from <yourTable> group by memberName having count(*) > 1

EDIT:
or this:

select * 
from yourTable as yt
where  exists
       (select name from yourTable where name = yt.nm and ID != yt.ID)
order by name



Be One with the Optimizer
TG

Edited by - TG on 02/04/2014 16:52:21
Go to Top of Page

JohnConklin
Starting Member

USA
2 Posts

Posted - 02/04/2014 :  17:09:37  Show Profile  Reply with Quote
Thanks, I will give this a try to see if it gives me the results I am looking for.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000