Demo for http://stackoverflow.com/questions/8346394/sql-remove-duplicates-slightly-different

0

Please login or register to vote for this query.

(click on this box to dismiss)

SO question http://stackoverflow.com/questions/8346394/sql-remove-duplicates-slightly-different

Stack Overflow

Q&A for programmers

-- Demo
-- SO question http://stackoverflow.com/questions/8346394/sql-remove-duplicates-slightly-different

create table #tbl(unique_ID int, worker_ID int, date int, type_ID int)
insert into  #tbl values
  (1,1,500,1),(2,1,null,1)


select
  unique_ID,
  worker_ID,
  type_ID
into #validActive
from
  #tbl
where date is not null

select
  unique_ID,
  worker_ID,
  type_ID
into #nullActive
from #tbl
where date is null

Delete from #tbl where unique_ID in
(
select #nullActive.unique_ID from #validActive join #nullActive on #validActive.worker_ID = #nullActive.worker_ID
where (#validActive.worker_ID = #nullActive.worker_ID and #validActive.type_ID = #nullActive.type_ID)
)

select * from #tbl

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results