Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 ytwhere exists (select name from yourTable where name = yt.nm and ID != yt.ID)order by name
Be One with the OptimizerTG
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.