delete tb1 where not exists(select * from tb2 where tb2.key = tb1.key)
樓主的意思是在DataTable對象的實例中進行操作?
问题是:我现在的datatable是内存的表,不能执行sql操作,谢谢帮忙。
对阿,是对datatable对象进行操作。
--例子--create table tb1(id int,c int) insert tb1 select 1,1 union select 2,1 union select 3,1create table tb2(id int,c int) insert tb2 select 1,1 union select 5,1 union select 6,1--先删除tb1中不在tb2中的记录 delete a from tb1 a left join tb2 b on a.id = b.id where b.id is null--再先删除tb2中不在tb1中的记录 delete a from tb2 a left join tb1 b on a.id = b.id where b.id is nullselect * from tb1 select * from tb2 drop table tb1,tb2
insert tb1
select 1,1
union select 2,1
union select 3,1create table tb2(id int,c int)
insert tb2
select 1,1
union select 5,1
union select 6,1--先删除tb1中不在tb2中的记录
delete a
from tb1 a left join tb2 b on a.id = b.id
where b.id is null--再先删除tb2中不在tb1中的记录
delete a
from tb2 a left join tb1 b on a.id = b.id
where b.id is nullselect * from tb1
select * from tb2
drop table tb1,tb2