SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to fetch duplicate records


How to fetch duplicate records

Author
Message
girish.nehte-1109699
girish.nehte-1109699
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 38
Hi,

I am using SQL Server 2010 with Visual Studio for my application. Now I have a table say "EmEmployeesand that have some 5000 records. This table has a column "Name" which is not a primary field. There is a possibility of more than one records having same name. Now I have to fetch all the records having duplicate names. What should be the efficient way to do this?

Please let me know.

Regards,
Girish
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12754 Visits: 4077
girish.nehte-1109699 (1/23/2013)
Hi,

I am using SQL Server 2010 with Visual Studio for my application. Now I have a table say "EmEmployeesand that have some 5000 records. This table has a column "Name" which is not a primary field. There is a possibility of more than one records having same name. Now I have to fetch all the records having duplicate names. What should be the efficient way to do this?

Please let me know.

Regards,
Girish
to get the faster and possible correct help , always post table definition , sampled data plus expected output. see the link in my signature

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12754 Visits: 4077
select name from 
(
select name, row_number() over ( partition by name order by name ) rnk
from EmEmployeesand
) t where t.rnk > 1



-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33321 Visits: 16649
Yes, or use GROUP BY and HAVING. Sounds suspiciously like an interview or homework question to me.

John
lestatf4
lestatf4
Valued Member
Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)

Group: General Forum Members
Points: 62 Visits: 82
select <field list req'd>
from <your table>
where <field with dupes> in (select <field with dupes> from <your table> group by <field with dupes>
having count(*) > 1)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search