从一个表中如何剔除一部分数据
表2是表1的子集,现在希望从表一选取不含表2的数据, 就是集合A-B
作者: finkle_zhang 发布时间: 2011-06-10
SQL code
id是两表关联的主键
select * from 表1 a where not exists(select 1 from 表2 b where a.id=b.id)
id是两表关联的主键
作者: FlySQL 发布时间: 2011-06-10
SQL code
select * from 表1 a where not exists(select 1 from 表2 b where a.id=b.id)
作者: chuanzhang5687 发布时间: 2011-06-10
SQL code
select * from a where checksum(*) not in (select checksum(*) from b)
作者: fredrickhu 发布时间: 2011-06-10
引用 3 楼 fredrickhu 的回复:
SQL code
select
*
from
a
where
checksum(*)
not in
(select checksum(*) from b)
SQL code
select
*
from
a
where
checksum(*)
not in
(select checksum(*) from b)
这个绝对好
作者: cd731107 发布时间: 2011-06-10
SQL code
SELECT * FROM tb1 EXCEPT SELECT * FROM tb2 --结果是A-B后,并且去除重复记录
作者: wwwwgou 发布时间: 2011-06-10
引用 3 楼 fredrickhu 的回复:
SQL code
select
*
from
a
where
checksum(*)
not in
(select checksum(*) from b)
SQL code
select
*
from
a
where
checksum(*)
not in
(select checksum(*) from b)
这个比较牛些 学习了
作者: qq574444572 发布时间: 2011-06-10