Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Finding multiple records for individuals

Author  Topic 

JohnConklin
Starting Member

2 Posts

Posted - 2014-02-04 : 15:48:49
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
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-02-04 : 16:46:01
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
Go to Top of Page

JohnConklin
Starting Member

2 Posts

Posted - 2014-02-04 : 17:09:37
Thanks, I will give this a try to see if it gives me the results I am looking for.
Go to Top of Page
   

- Advertisement -