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
 General SQL Server Forums
 New to SQL Server Programming
 How to find duplicates

Author  Topic 

nicky_river
Yak Posting Veteran

55 Posts

Posted - 2010-10-18 : 08:28:35
How do i only find duplicate records in a table, which is given below.

A B
1 abc
1 def
1 ggg
2 serg
3 awer

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-18 : 08:41:18
By record i understand all the selected columns.
In the data posted by you I don't see any duplicate records.

To start with:

Select <columns >
From <your table>
Group by <Columns selected in select statement>
Having count(*) >1
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-18 : 09:29:15
select * from table
where id in (select id from table group by id having count(*) > 1)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

shaggy
Posting Yak Master

248 Posts

Posted - 2010-10-18 : 11:26:27
declare @t table (col1 int)

insert @t

select 1
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 5
union all
select 6
union all
select 7
union all
select 8

select col1 from (
select ROW_NUMBER() over (partition by col1 order by col1) rno,* from @t )a
where rno > 1
Go to Top of Page
   

- Advertisement -