更新时间:2023-02-04 21:43:19
select em.emp_id, em.first_name从emp_master em 离开加入passport_details pd在 pd.emp_id = em.emp_id 和 pd.status = 1其中 pd.emp_id 为空
我没有要测试的 3.23 实例,但这应该可以.
I've 2 tables, emp_master and passport_details.
emp_master(emp_id,first_name,email_id,dob,doj,status.........)
passport_details(id, emp_id,passport_number,given_name,......).
I am trying to fetch emp_id and first_name from emp_master who have not entered passport_details.
I tried different combination of SubQueries, used NOT IN, NOT EXISTS.
SELECT emp_id,first_name
FROM emp_master
WHERE emp_id NOT IN(SELECT emp_id FROM passport_details WHERE status=1);
I am getting error
You have an error in your SQL syntax near 'SELECT emp_id FROM passport_details WHERE status=1)' at line 3
I am using MySQL 3.23.
My question is
- Do MySQL 3.23 supports SubQueries?
- What could be the optimal query to fetch emp_id and first_name from emp_master who have not entered passport_details.
select em.emp_id, em.first_name
from emp_master em left join passport_details pd
on pd.emp_id = em.emp_id and pd.status = 1
where pd.emp_id is null
I don't have a 3.23 instance to test with, but this should work.