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 2000 Forums
 Transact-SQL (2000)
 Duplicate Values

Author  Topic 

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2004-08-27 : 11:45:57
I am trying to write a query that will give me the duplicates in a table. For example:

ID FirstName Lastname Extension
1 Bob David 4325
2 Steve Kerr 2345
3 Joe Plum 4325
4 Dan Man 8934

I want to return ID 1 and 3 since they are dups. Please help!

gpl
Posting Yak Master

195 Posts

Posted - 2004-08-27 : 11:54:35
try this

Select ID, YT.Extension
from {YourTableName} YT
Join
(
select Extension, count(*)
from {YourTableName}
group by Extension
having Count(*) > 1
) DT
on YT.Extension = DT.Extension


Graham
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-27 : 11:57:12
select *
from MyTable t1
inner join
(select Extension from MyTable group by Extension having Count(*)>1) t2 on t1.Extension = t2.Extension

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2004-08-27 : 12:07:30
Thanks! That worked!!!
Go to Top of Page
   

- Advertisement -