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 !
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
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
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 !
thank you it worked !!
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