SQL学习:not exists用法
与 not in 的效果一样, 但这个效率相对高一点
例如:
a1表:id name
1 张三
2 李四
a2表:id name
1 张三
2 李四
刚使用的新手用法可能是这样子的, 以为跟 not in 一样,但是下面这样写达不到预期效果
select * from a1
where a1.name not exists (
select 1 from a2
);
事实上是这样子的,需要子查询跟主查询有关联
select * from a1
where a1.name not exists (
select 1 from a2 where a2.name = a1.name
);