日期:2014-05-18 浏览次数:20513 次
--记得用测试库哈~! delete t from 原表 t left join 参照数据表 e on t.字段1 = e.字段1 and t.字段2 = e.字段2 where e.字段1 is null
------解决方案--------------------
DELETE T FROM T WHERE NOT EXISTS(SELECT 1 FROM TC WHERE COL1=T.COL1 AND COL2=T.COL2)
?
------解决方案--------------------
CREATE TABLE TA (COL1 VARCHAR(12),COL2 VARCHAR(12)) INSERT TA SELECT 'A','a1' union select 'A','a2'union select 'B','b1' union select 'C','c1' delete from ta where not exists (select 1 from ( select * from TA where (col1='A' AND col2='a1') or (col1='C' AND col2='c1'))a where col1=ta.col1 and a.col2=ta.col2) /* COL1 COL2 A a1 C c1 */
------解决方案--------------------
delete from tab where not exists ( select * from tab where A='a1' and C='c1')