Last answered:

19 Nov 2021

Posted on:

13 Nov 2021

0

Resolved: i always retrieve 36 rows !!

I retrieved 36 rows and when I applied the code you written retrieved 37 rows and you said we have to retrieve 42 rows. what's the problem !

5 answers ( 1 marked as helpful)
Instructor
Posted on:

14 Nov 2021

0

Hi Hazem!

Thanks for reaching out.

Can you please support your question by providing the exact code you've executed, so that we can be sure that we're all referring to the same query?
Also, can you please double-check the content of the dept_manager table prior to executing this query? How many records are stored in that table?

Hope this helps.
Best,
Martin

Posted on:

14 Nov 2021

0

the code <>
*-----------------*------------------------*-------------------------
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 dm.emp_no
                         from dept_manager dm
                         where dm.emp_no=110022
                       ) as manager_id
    from employees e
        join dept_emp de on de.emp_no =e.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 dm.emp_no
from dept_manager dm
where dm.emp_no=110039
   ) as manager_id
from employees e
join dept_emp de on de.emp_no =e.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 dm.emp_no
from dept_manager dm
where dm.emp_no=110039
   ) as manager_id
from employees e
join dept_emp de on de.emp_no =e.emp_no
where e.emp_no=10022
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 dm.emp_no
from dept_manager dm
where dm.emp_no=110022
   ) as manager_id
from employees e
join dept_emp de on de.emp_no =e.emp_no
where e.emp_no=10039
GROUP BY e.emp_no   )as d ) as u ;
-----*------------*----------------*-------------------------*----------------------------



22 record in dept_manager table

image.png

Posted on:

16 Nov 2021

0

Hey I just checked your code you just need to change the where clause in subset C from where e.emp_no=10022 to where e.emp_no=110022. You missed a 1 in front. Hope it's helpful. Cheers !

Posted on:

19 Nov 2021

0

thank you it worked !!

Instructor
Posted on:

19 Nov 2021

0

Hi Vigneshwari and hazem!

Thanks for reaching out!
@Vigneshwari: Thank you for sharing your solution with hazem!!!

Good luck and please feel free to post another question should you encounter any difficulties. Thank you.

Best,
Martin

Submit an answer