是否可以编写一个查询来检查任一子查询是否正确而不是一个?
SELECT *
FROM employees e
WHERE NOT EXISTS
(
SELECT null
FROM eotm_dyn d
WHERE d.employeeID = e.id
) OR (select * FROM table c WHERE c.employeeID = e.id)
是的,只需将该OR
条件更改为另一个EXISTS
表达式:
SELECT *
FROM employees e
WHERE NOT EXISTS
(
SELECT null
FROM eotm_dyn d
WHERE d.employeeID = e.id
)
AND NOT EXISTS
(
select null
FROM table c
WHERE c.employeeID = e.id
)
也猜测你的意图。这将检查两个子查询的记录是否不存在。如果您要检查一个或另一个,我不确定您的意思。
更新:再次尝试想象,也许您打算做一个OR EXISTS
:
SELECT *
FROM employees e
WHERE NOT EXISTS
(
SELECT null
FROM eotm_dyn d
WHERE d.employeeID = e.id
)
OR EXISTS
(
select null
FROM table c
WHERE c.employeeID = e.id
)
这将在employees
其中找到不在或不在的记录。eotm_dyn
table
你的问题有点难以理解,但我猜这就是你所要求的。它将返回employees
表中没有任何相关行的表eotm_dyn
和table
.
SELECT *
FROM employees e
WHERE e.id NOT IN
(
(SELECT employeeID
FROM eotm_dyn)
UNION
(SELECT employeeID
FROM table)
)