Last answered:

13 Nov 2024

Posted on:

13 Nov 2024

0

Resolved: got output of 43 rows instead of 26

I used this code but it gives 43 rows, what can I do to make it give me 26 rows

SELECT
    m.dept_no, m.emp_no, d.dept_name
FROM
    departments_dup d
        LEFT JOIN
    dept_manager_dup m ON m.dept_no = d.dept_no
ORDER BY m.dept_no; 
1 answers ( 1 marked as helpful)
Instructor
Posted on:

13 Nov 2024

0

Hi Nada!
Thanks for reaching out.

When using the LEFT JOIN the order of the tables matters. So, you should exchange the tables like this:

SELECT
    m.dept_no, m.emp_no, d.dept_name
FROM
    dept_manager_dup m
        LEFT JOIN
     departments_dup d ON m.dept_no = d.dept_no
ORDER BY m.dept_no; 

Hope this helps.
Best,
Tsvetelin

Submit an answer