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

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

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

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

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

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

只需判断一下即可,根据你的题目意思应该是a表的id和b表的id相关联。 select *, case when (select count(*) from b where id = a.id)>0 then 1 else 0 end as flag from a如果你是想a表和b表的字段和id这两列都一样,才将flag显示为1的话,用下...

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

insert into tableA select * from tableB b where not exists(select 1 from tableA a where a.id = b.id) insert into tableA select * from tableB b left join tableA a on a.id = b.id where a.id is null ----用 not exists来判断,left jo...

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.字段)

假定通过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

你这两个表示什么关系 是有主外键关系还是怎么样 如果有主外键关系 直接用主键查询 问题太抽象了 没法上sql语句

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