日期:2014-05-18  浏览次数:20332 次

跨表删除的问题,大伙进来看看~
如果对比2表,查询表B,如果在表A中不存在的,删除表B中的行

表A:
id       hy           isok
1         001             1
2         002             1

……

表B:

id       hy          
1         001            
2         002  
3         003    
       
……

如表所示,运行后应该删除   表B   中的   第3行


------解决方案--------------------
delete B
where checksum(id,hy) not in (select checksum(id,hy) from A)
------解决方案--------------------
delete from B where not exists(select 1 from A where A.id=B.id and A.hy=B.hy)