Last answered:

22 Feb 2023

Posted on:

08 Nov 2021

0

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?
SELECT
    e.emp_no AS employee_id,
    min(dm.dept_no) AS department_code,
    (SELECT
            emp_no
        FROM
            dept_manager
        WHERE
            emp_no = 110022) AS manager_id
FROM
    employees e
        JOIN
    dept_manager dm ON e.emp_no = dm.emp_no
WHERE
    e.emp_no <= 10020
GROUP BY e.emp_no
ORDER BY e.emp_no;

3 answers ( 0 marked as helpful)
Posted on:

08 Nov 2021

2

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:

image.png
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.

Posted on:

09 Nov 2021

0

thanks a lot!

Posted on:

22 Feb 2023

0

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.

Submit an answer