Mysql 将嵌套子查询转换为简单查询
有两个表“雇员”和“分配”。有人能帮我把这个嵌套查询转换成一个简单的查询(使用连接或任何东西)吗。我的意思是我不想要嵌套查询。下面是运行良好的查询Mysql 将嵌套子查询转换为简单查询,mysql,join,subquery,Mysql,Join,Subquery,有两个表“雇员”和“分配”。有人能帮我把这个嵌套查询转换成一个简单的查询(使用连接或任何东西)吗。我的意思是我不想要嵌套查询。下面是运行良好的查询 select emp_id, emp_name from employees where emp_id not in (select emp_id from allocation where emp_id is not null and date_assignedUpto is null
select emp_id, emp_name from employees
where emp_id not in (select emp_id from allocation
where emp_id is not null
and date_assignedUpto is null
group by emp_id);
如果您确实不想在查询中使用
not,可以这样做:
SELECT e.emp_id, e.emp_name FROM employees e
LEFT JOIN (SELECT emp_id FROM allocation
WHERE emp_id IS NOT NULL
AND date_assignedUpto IS NULL
GROUP BY emp_id) a
ON e.emp_id= a.emp_id;
你的问题和我的问题都不一样。它给出了不同的答案。顺便说一句,谢谢,现在我对建立查询有了一些想法。对不起,查询中没有我只想到的内容。请查看更新的答案。。。。。