pdlr.net
当前位置:首页 >> SQL中,如何查询存在一个表而不在另一个表中的数据... >>

SQL中,如何查询存在一个表而不在另一个表中的数据...

select * from swdj where qymc not in (select qymc from gsdj)

SELECT * FROM A WHERE id NOT IN ( SELECT id FROM B);或者SELECT * FROM A WHERE NOT EXISTS ( SELECT 1 FROM B WHERE B.id = A.id );或者SELECT A.* FROM A LEFT JOIN B ON (A.id = B.id)WHERE b.id IS NULL

select *from card where username not in(select username from user)

1. 采用not exists 执行速度快delete from T_AD where not exists (select 1 from T_AD_PLAY where T_AD.N_CODE =T_AD_PLAY.N_CODE ) 2. 采用not in 执行速度慢Delete From T_AD Where N_AD Not In(Select N_AD From T_AD_PLAY)

假定通过id字段关联 1) select * from A where id not in (select id from B) 2) select A.* from A LEFT JOIN B ON A.id = B.ID WHERE B.ID IS NULL

select * from 表1 where 字段 not in (select 字段 from 表2) 若是还要考虑到表二有,而表一没有的的情况 select * from 表1,表2 where 字段 not in (select 字段 from 表1 inner join 表2 on 表1.字段=表2.字段)

select 字段 from 表1 where 关键字段 not in (select 关键字段 from 表2) 应该你懂

select top 1 * from tb2 where id not in (select [index] from tb1) order by id

假设表table1,列a,表table2,列b select a from table1 where a not in ( select b from table2 )

select * from swdj where qymc not in (select qymc from gsdj)

网站首页 | 网站地图
All rights reserved Powered by www.pdlr.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com