0

Image contains two tables, Now I want to delete duplicate table from table 1 with comparing data with table 2

Like, I want to Delete one row containing 234 and keep another row only, and so on.

**Note: I am using IBM DB2 as database.

Puskarkc007
  • 174
  • 2
  • 14
  • 1
    http://stackoverflow.com/questions/595433/how-can-i-compare-two-tables-and-delete-the-duplicate-rows-in-sql – StackUseR Nov 29 '16 at 11:31

2 Answers2

0
delete from table1 f0
where rrn(f0) in 
(
    select f3.rw from (
                    select rrn(f1) rw, 
                    rownumber() over(partition by Policy) rang 
                    from table1 f1 inner join table2 f2 on f1.policy=f2.policy
                   ) f3 
     where f3.rang=1
)
Esperento57
  • 16,521
  • 3
  • 39
  • 45
-1

delete top(select count(a.Policy)-1 From Table1 x where x.policy in (Select distinct policy from table2)) From Table1

Abhishek
  • 1
  • 1
  • Please Format your Code and describe your answer in few lines, thanks, To format as code expand your code with 4 spaces at left – hmmftg Nov 29 '16 at 11:58