Last answered:

08 Feb 2023

Posted on:

07 Feb 2023

0

Another Solution Using COALESCE

Is this one correct?

it uses 22 rows of code and returns 40 rows

SELECT 
    emp_no as emp_id, dept_no as dept_id, manager_id
FROM
    ((SELECT 
        emp_no,
            dept_no,
            MAX(from_date),
            COALESCE(110022) AS manager_id
    FROM
        dept_emp
    WHERE
        emp_no <= 10020 AND emp_no >= 10001
    GROUP BY emp_no) UNION (SELECT 
        emp_no,
            dept_no,
            MAX(from_date),
            COALESCE(110039) AS manager_id
    FROM
        dept_emp
    WHERE
        emp_no <= 10040 AND emp_no >= 10021
    GROUP BY emp_no)) AS a;
1 answers ( 0 marked as helpful)
Instructor
Posted on:

08 Feb 2023

0

Hi Eslam!
Thanks for reaching out.

Yes this is also a valid solution.

Hope this helps.
Best,
Tsvetelin

Submit an answer