【发布时间】:2020-08-16 14:46:41
【问题描述】:
我已经阅读了许多与此相关的答案,并且所有人都说两者的工作原理几乎相同,除了在空值的情况下,而不是在单个列的情况下。
任务是在 invoice_line_items 表中查找从未分配给任何行项目的每个帐号:
正确的查询是:
SELECT
account_number, account_description
FROM
general_ledger_accounts gl
WHERE
NOT EXISTS( SELECT
account_number
FROM
invoice_line_items
WHERE
gl.account_number = account_number);
如果我删除 gl.account_number = account_number 它返回零行。
我想知道:
1 ) 为什么在子查询中需要声明 gl.account_number = account_number。
2 ) Not In 和 Not Exists 中的选择过程有何不同。
【问题讨论】:
-
我没有完全理解你的问题。您的代码与
not exists完全不同。 -
@GordonLinoff 我想知道为什么要在子查询中使用 gl.account_number = account_number?
标签: mysql sql rdbms not-exists notin