在gaussdb中建测试表如下:
create table ypg_20240227(id varchar, name varchar);
INSERT into ypg_20240227 VALUES (‘1’,‘one’);
INSERT into ypg_20240227 VALUES (‘2’,‘two’);
create table ypg_20240228(id varchar);
INSERT into ypg_20240228 VALUES (‘1’);
以下2种写法等价:
select * from tpods.ypg_20240227 a where id in (select id from ypg_20240228 b);
1 one
select * from tpods.ypg_20240227 a where EXISTS (select 1 from ypg_20240228 b where a.id = b.id);
1 one
select * from tpods.ypg_20240227 a where id not in (select id from ypg_20240228 b);
2 two
select * from tpods.ypg_20240227 a where not EXISTS (select 1 from ypg_20240228 b where a.id = b.id);
2 two