Id like to ask if this is ok.
select * from (select t1.emp_no as emp, t2.dept_no as dept ,
(select emp_no from dept_manager where emp_no = 110022) as manager
from employees as t1
join
dept_emp as t2 on t1.emp_no = t2.emp_no
where t1.emp_no <= 10020 or t1.emp_no = '110039'
group by t1.emp_no, t2.dept_no
order by emp) as A
union
select * from (select t1.emp_no as emp, t2.dept_no as dept ,
(select emp_no from dept_manager where emp_no = 110039) as manager
from employees as t1
join
dept_emp as t2 on t1.emp_no = t2.emp_no
where t1.emp_no between '10021' and '10040' or t1.emp_no = '110022'
group by t1.emp_no, t2.dept_no
order by emp) as b
order by emp;
(select emp_no from dept_manager where emp_no = 110022) as manager
from employees as t1
join
dept_emp as t2 on t1.emp_no = t2.emp_no
where t1.emp_no <= 10020 or t1.emp_no = '110039'
group by t1.emp_no, t2.dept_no
order by emp) as A
union
select * from (select t1.emp_no as emp, t2.dept_no as dept ,
(select emp_no from dept_manager where emp_no = 110039) as manager
from employees as t1
join
dept_emp as t2 on t1.emp_no = t2.emp_no
where t1.emp_no between '10021' and '10040' or t1.emp_no = '110022'
group by t1.emp_no, t2.dept_no
order by emp) as b
order by emp;
1 answers ( 0 marked as helpful)
Hi Kiran!
Thanks for reaching out.
Yes, your query works fine. The manager to employees from 10001 to 10020 is 110022 and the manager from 10021 to 10040 is 110039. Also the manager to employees with number 110022 is 110039 and vice versa. Bravo!
Hope this helps.
Best,
Tsvetelin
Thanks for reaching out.
Yes, your query works fine. The manager to employees from 10001 to 10020 is 110022 and the manager from 10021 to 10040 is 110039. Also the manager to employees with number 110022 is 110039 and vice versa. Bravo!
Hope this helps.
Best,
Tsvetelin