如何用SQL语句求两个表的差集?(200分)

  • 主题发起人 主题发起人 BLUE_SKY
  • 开始时间 开始时间
B

BLUE_SKY

Unregistered / Unconfirmed
GUEST, unregistred user!
[red]有两个表A,B,A中包含了B中的所有记录,现在要用SQL语句将这些记录删去,将结果保存到表C中,怎么写?[/red]
 
insert into C select A.* from A where A.关键字 not in (select B.关键字 from B);
 
表中有没有关键值?假如有关键值id
insert into c
select * from a where id not in (select id from b)
 
用not exists 子句,我已经搞定了
 
delete from a where a.key in (select id from b)
insert into c
select * from a
 
楼上都说了。很好实现的。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
751
SUNSTONE的Delphi笔记
S
S
回复
0
查看
758
SUNSTONE的Delphi笔记
S
D
回复
0
查看
890
DelphiTeacher的专栏
D
后退
顶部