Last answered:

16 Apr 2020

Posted on:

12 Apr 2020

0

SQL Subqueries nested in SELECT and FROM - solution 2

Hey team! I can't download the solution posted in the SQL Subqueries nested in SELECT and FROM - solution 2 part of the sql course. I tried using chrome, safari and mozilla but the download didn't work. Highly appreciate if you can help me on this.
1 answers ( 0 marked as helpful)
Instructor
Posted on:

16 Apr 2020

0
Hi Paul! Thanks for reaching out! In similar situations, please try using another browser to download the necessary course resources - this sometimes helps. Otherwise, please find the code pasted below. Thank you. Hope this helps.
Best,
Martin
INSERT INTO emp_manager
SELECT
u.*
FROM
(SELECT
a.*
FROM
(SELECT
e.emp_no AS employee_ID,
MIN(de.dept_no) AS department_code,
(SELECT
emp_no
FROM
dept_manager
WHERE
emp_no = 110022) AS manager_ID
FROM
employees e
JOIN dept_emp de ON e.emp_no = de.emp_no
WHERE
e.emp_no <= 10020
GROUP BY e.emp_no
ORDER BY e.emp_no) AS a UNION SELECT
b.*
FROM
(SELECT
e.emp_no AS employee_ID,
MIN(de.dept_no) AS department_code,
(SELECT
emp_no
FROM
dept_manager
WHERE
emp_no = 110039) AS manager_ID
FROM
employees e
JOIN dept_emp de ON e.emp_no = de.emp_no
WHERE
e.emp_no > 10020
GROUP BY e.emp_no
ORDER BY e.emp_no
LIMIT 20) AS b UNION SELECT
c.*
FROM
(SELECT
e.emp_no AS employee_ID,
MIN(de.dept_no) AS department_code,
(SELECT
emp_no
FROM
dept_manager
WHERE
emp_no = 110039) AS manager_ID
FROM
employees e
JOIN dept_emp de ON e.emp_no = de.emp_no
WHERE
e.emp_no = 110022
GROUP BY e.emp_no) AS c UNION SELECT
d.*
FROM
(SELECT
e.emp_no AS employee_ID,
MIN(de.dept_no) AS department_code,
(SELECT
emp_no
FROM
dept_manager
WHERE
emp_no = 110022) AS manager_ID
FROM
employees e
JOIN dept_emp de ON e.emp_no = de.emp_no
WHERE
e.emp_no = 110039
GROUP BY e.emp_no) AS d) as u;

Submit an answer