Mysql Lab 2: Question Set 1
Mysql Lab 2: Question Set 1
Mysql Lab 2: Question Set 1
EMP TABLE:
DEPT TABLE:
Ans 3) select * from emp e ,dept d where (dname = ‘SALES’ or dname =’RESEARCH’ ) and e.deptno =
d.deptno order by e.deptno asc; (OR)
select * from emp e ,dept d where d.dname in (‘SALES’,’RESEARCH’) and e.deptno = d.deptno order by
e.deptno asc;
Ans 5) select * from emp where sal=(select max(sal) from emp where sal<( select max(sal) from emp));
Ans 6)select * from emp where sal>any(select sal from emp where dept_no=10);
Ans 7) select Ename, d.dept_no,d.d_name from emp e,dept d where e.dept_no(+)=d.dept_no and
d.dept_no IN(select dept_no from dept where d_name IN(‘SALES’,’OPERATION’));
Ans 8)select job from emp where dept_no=(select dept_no from dept where d_name=’RESEARCH’)
intersect select job from emp where dept_no=(select dept_no from dept where
d_name=’ACCOUNTING’) order by job;
Ans 9) select job from emp where dept_no=(select dept_no from dept where d_name=’SALES’) union
select job from emp where dept_no=(select dept_no from dept where d_name=’ACCOUNTING’) ;
Ans 10) select e.ename,e.job, months_between(sysdate,hiredate) exp ,d.dname,d.loc from emp e ,dept
d where e.deptno = d.deptno and e.empno in (select mgr from emp ) ;
Ans 11) select d.dname,count(*) from emp e,dept d,where e.deptno = d.deptno and
e.job = 'CLERK' group by d.dname having count(*) >= 2;
Ans 12) select distinct W.empno,W.ename,W.sal from (select w.empno,w.ename,w.sal from emp
w,emp m where w.mgr = m.empno and w.sal<m.sal) W (select * from emp where empno in (select mgr
from emp)) where W.sal > A.sal; (OR)
select * from emp w,emp m where w.mgr = m.empno and w.sal < m.sal and w.sal > any (select sal from
emp where empno in (select mgr from emp));
Ans 13) select e.ename,e.job,e.sal,d.dname from emp e ,dept d where e.deptno = d.deptno and e.job
not in('CLERK') order by e.sal desc;
Ans 14) select * from emp m where m.empno in (select mgr from emp) and m.sal > (select avg(e.sal)
from emp e where e.mgr = m.empno ) ;
The subquery does the same as (select (avg(e.sal)),m.ename from emp e, emp m where
e.mgr=m.empno group by e.mgr,m.ename);