15. sql subquires--Can you please help to find out why in the video you are using the dept_emp table
Can you please help to find out why in the video you are using the dept_emp table instead of the dept_manager table?
e.emp_no AS employee_id,
min(dm.dept_no) AS department_code,
emp_no = 110022) AS manager_id
dept_manager dm ON e.emp_no = dm.emp_no
e.emp_no <= 10020
GROUP BY e.emp_no
ORDER BY e.emp_no;
Because we need to extract data about the department each employee is part of. This can only be fetched from the dept_emp table which contains (emp_no, dept_no, from_date, to_date) as you see in the following result set:
If you used the dept_manager table, then you will instead be extracting the dept_no of the manager himself not the dept_no of the employee.
I hope I was able to explain.
thanks a lot!
I was just wondering the same thing because at minute 4:08 he literally said: 'what we are doing here is joining the Employees and the Department Manager tables'.
but he actually put dept_emp.
thanks for the explanation.