Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 将嵌套子查询转换为简单查询_Mysql_Join_Subquery - Fatal编程技术网

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;

你的问题和我的问题都不一样。它给出了不同的答案。顺便说一句,谢谢,现在我对建立查询有了一些想法。对不起,查询中没有我只想到的内容。请查看更新的答案。。。。。