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)
 Duplicates

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-31 : 09:01:52
Dave writes "have a table called extract file and I need to a duplicate query on id field but I only want duplicates in different states not in the same states.

I want to see only duplicates in different duplicates of id in various states

This is what the current code that I am using looks like

SELECT TOP 100 PERCENT State, [Debt Number], ID, [Last Name], [First Name]
FROM dadedeji.[Extract File]
WHERE (ID IN
(SELECT [ID]
FROM dadedeji.[Extract File] AS Tmp
GROUP BY [ID]
HAVING COUNT(*) > 1))AND (State<>State)
ORDER BY SSN, State"

nr
SQLTeam MVY

12543 Posts

Posted - 2006-01-31 : 11:10:48
select *
from tbl t1
where exists (select * from tbl t2 where t2.id = t1.id and t2.state <> t1.state)

select id
from tbl
group by id
having count(distinct state) > 1


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -