带有NOT IN子句的子查询出现时,LEFT JOIN是否有可能失败? [英] Is it possible that LEFT JOIN fails while subquery with NOT IN clause suceeds?

查看:238
本文介绍了带有NOT IN子句的子查询出现时,LEFT JOIN是否有可能失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一段时间我已经发布了对此问题的答案 PostgreSQL多条件语句.

A while I have posted an answer to this question PostgreSQL multiple criteria statement.

任务非常简单-如果另一个表中没有相应的值,则从一个表中选择值.假设我们有如下表:

Task was quite simple - select values from one table if there is no corresponding value in another table. Assuming we have tables like below:

CREATE TABLE first  (foo numeric);
CREATE TABLE second (foo numeric);

我们希望从first.foo获取所有值,而second.foo中不会出现这些值.我提出了两种解决方案:

we would like to get all the values from first.foo which doesn’t occur in the second.foo. I've proposed two solutions:

  • 使用LEFT JOIN
SELECT first.foo
FROM first
LEFT JOIN  second 
ON first.foo = second.foo
WHERE second.foo IS NULL;

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆