表数据如下:
-----------------
A a1 ...其他字段
A a2
B b1
C c1
------------------
现在想根据前两个字段删除数据,
例如有数据:
A a1
C c1
我想把前两个字段不是这个的都删了(即删掉A a2和B b1),sql语句怎么写
-----------------
A a1 ...其他字段
A a2
B b1
C c1
------------------
现在想根据前两个字段删除数据,
例如有数据:
A a1
C c1
我想把前两个字段不是这个的都删了(即删掉A a2和B b1),sql语句怎么写
--记得用测试库哈~!
delete t
from 原表 t left join 参照数据表 e on t.字段1 = e.字段1 and t.字段2 = e.字段2
where e.字段1 is null
?
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')可以???