如何查询表A中的某字段的值在表B中不存在?

1、测试表创建,插入数据:

create table a
(id int,
name varchar2(10));
 
create table b
(id int);
 
insert into a values (1,'a');
insert into a values (2,'b');
insert into a values (3,'c');
insert into a values (4,'d');
insert into a values (5,'e');
 
insert into b values (1);
insert into b values (3);

2、查询b表中存在的id不出现在a表中的内容,可用语句:

select * from a where id not in (select id from b);

3、结果:

demo

查询泊位表中地磁编号在地磁表中没有的

SELECT P.GEIMAGNETIC_ID FROM PARK P  WHERE P.GEIMAGNETIC_ID NOT IN (SELECT EQUIP_ID FROM GEIMAGNETIC G)

select equip_id,PARKLOTS,PARK_ID from GEIMAGNETIC  where equip_id not in (select GEIMAGNETIC_ID  from park p);

 

展开阅读全文

没有更多推荐了,返回首页