|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, March 11, 2013 7:33 AM
Points: 3,
Visits: 11
|
|
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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
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---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
select name from ( select name, row_number() over ( partition by name order by name ) rnk from EmEmployeesand ) t where t.rnk > 1
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 8:51 AM
Points: 4,425,
Visits: 7,187
|
|
Yes, or use GROUP BY and HAVING. Sounds suspiciously like an interview or homework question to me.
John
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:43 AM
Points: 12,
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)
|
|
|
|