sql如何删除某两张表中不相同的的数据,以某一字段为比较
4个回答
展开全部
declare @a table(id int)
insert into @a
select 1
union select 2
union select 3
union select 4
declare @b table(id int)
insert into @b
select 1
union select 2
union select 6
union select 5
select * from @a a inner join @b b on a.id=b.id
delete from @a where id not in (select id from @b)
delete from @b where id not in (select id from @a)
select * from @a
select * from @b
insert into @a
select 1
union select 2
union select 3
union select 4
declare @b table(id int)
insert into @b
select 1
union select 2
union select 6
union select 5
select * from @a a inner join @b b on a.id=b.id
delete from @a where id not in (select id from @b)
delete from @b where id not in (select id from @a)
select * from @a
select * from @b
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这不是都回答了吗,咋看不懂啊。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
依楼上的事例:
DELETE FROM 表B WHERE C not in (SELECT C FROM A)
DELETE FROM 表B WHERE C not in (SELECT C FROM A)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |