如何查询表A中的某字段的值在表B中不存在?
用not in语句来实现。
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、结果:
1、创建测试表,
create table test_tbl_a(num number);
create table test_tbl_b(num number);
2、插入测试数据;
insert into test_tbl_a values (1);
insert into test_tbl_a values (2);
insert into test_tbl_b values (1);
insert into test_tbl_b values (2);
insert into test_tbl_b values (3);
insert into test_tbl_b values (4);
commit;
3、查询B表中全量数据;select t.*, rowid from test_tbl_b t;
4、编写巧陪语句,查询B中所孝扒蠢有在A中不存此肢在的number;
select t.* from test_tbl_b t where not exists (select 1 from test_tbl_a b where t.num = b.num)
或
select B.* from B left join A on A.numer=B.number
where A.number is null