答案 0 :(得分:0)
我认为您不需要fk_case
用于SELECT,因为用户是否在其他项目上无关紧要。唯一的问题是他不在当前的人中。
SELECT DISTINCT users.id, users.firstName, users.lastName
FROM users
LEFT JOIN junc_jobs ON users.id = junc_jobs.fk_employee
WHERE users.fk_role > 1
AND (fk_case IS NULL OR fk_case != 66)
ORDER BY firstName
也不确定junc_jobs的功能,但也许这样可能有所帮助
SELECT u.*
FROM users u
WHERE u.fk_role > 1
AND NOT EXISTS ( SELECT 1
FROM junc_jobs j
WHERE j.fk_employee = u.id and j.fk_case = 66)
答案 1 :(得分:0)
将fk_case
测试放在ON
子句中,然后仅显示不匹配的用户。
SELECT DISTINCT u.id, u.firstName, u.lastName
FROM users as U
LEFT JOIN junc_jobs AS j ON u.id = j.fk_employee AND j.fk_case = 66
WHERE j.fk_case IS NULL AND u.fk_role > 1