日期:2014-05-19  浏览次数:20561 次

datatable 相减
请问,我现在有两个结构一样的datatable,我想按照主键把不一样的row去掉,如何操作?

------解决方案--------------------
delete tb1 where not exists(select * from tb2 where tb2.key = tb1.key)
------解决方案--------------------
樓主的意思是在DataTable對象的實例中進行操作?
------解决方案--------------------
--例子--

create table tb1(id int,c int)
insert tb1
select 1,1
union select 2,1
union select 3,1

create 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 null

select * from tb1
select * from tb2


drop table tb1,tb2