You are on page 1of 56

218.List the emps whose job is same as smith.

SQL>Sel ect * from emp where job = (select job from

emp whereena me=SMITH) ;219.List the emps who are senior to miller.SQL>Se lect * from emp

where hiredate <(select hiredate from emp where ename = 'MILLER') ;220.List the emps whos

e job is same as either allen or sal > allenSQL>Se lect * from emp where en ame <> 'ALLEN' AND(j

ob = (select job from emp where ename = 'ALLEN') or sal > (select sal from emp where ename = 'ALLEN'))

;221.List the emps who are senior to their own mgr.SQL>Sele ct A.* from emp A, emp

B whereA.mgr = B.empno and A.hiredate <(select B.hiredate from emp whereempno = B.empno) order

by A.hiredate ;222.List the emps whose s al > blakesS QL>Select A.* from emp A, emp B where A.sal >(select

sal from emp where B.ename = 'BLAKE'and emp.empno=B.e mpno) ;223.List the emps who belongs to dept 10

and sal > allens salSQL>Select A.* from emp A, emp B whereA.dept no = 10 and A.sal >(select sal

from emp where B.ename ='ALLEN' and emp.empno=B.e mpno) ;ORselect * from emp where deptno= 10 andsal >

(select sal from emp where ename='ALLEN') ;224.List the Mgrs who are senior to ki ng & who are junior to s

mith.SQL>Sele ct * from emp where job = 'MANAGER' an dhiredate < (select hiredate from emp where

ename = 'KING') andhiredate > (select hiredate from emp where ename = 'SMITH') ;225.List the empno, ename,

loc, sal, dname,loc of al l the emps belon g tokings deptSQL>Selec t empno, ename, sal, dn

ame, loc from e mp, dept, salgr adeWhere emp.deptno = (select deptno from emp where ename='KING')a ndemp.deptno =

dept.deptno and sal between losal and hisal226.List the emps whos e grade are > t he grade of mil ler.SQL>Select

emp.*, grade from emp, salgrade Where grade >(select grade from emp, salgrade Where ename =

'MILLER'and sal between losal and hisal) and sal between losal and hisal

227.List the emps who are belongs to dall as or Chicago with the gradesame as adams or exp more than

smith.SQL>Sel ect * from emp, dept, salgrade Where loc in('DALLAS','CH ICAGO') and (grade = (select

gradefrom emp,salgrade where ename='ADAMS' andsal between losal and hisal) or months_betw een(sysdate,hire

date)/12 >(select months_betwee n(sysdate,hireda te)/12 fromemp where ename = 'SMITH')) and ename not in ('ADAMS','SMIT

H')and emp.deptno = dept.deptno and sal between losal and hisal ;228.List the emps whose sal is same as

ford or blake.SQL>Sel ect * from emp where sal in (select sal from emp where ena mein(FORD,BL

AKE)) ;Select * from emp where sal in(select sal from emp where ename = 'FORD')UNION( select sal from emp where

ename = 'BLAKE') ;GIVING ERROR : Query block has incorrect no. of result columns.229.Li

st the emps whos e sal is same as any one of the following:a)Sal of any clerk of emp1 table.b)A

ny emp of emp2 joined before 83.c)The total remuneration (S al+comm.) of all sales person of salesdept belongs to emp2

table.d)Any grad e 4 emps sal of emp4 tablee) Any emp sal of emp5 tableSQL>Sel ect * from em p Wheresal in

(select sal from emp1 where job = 'CLERK') or sal in (select sal from emp2 where hiredate > '01-JAN-83' ) or sal in (select

sal+decode(com m,null,0) fromemp2,dept where dname='SALES' and emp2.deptno=de pt.deptno) or sal

in (select sal from emp4,salgrade where grade=4) or sal in (select sal from emp5) ;Select * from emp Where sal

in (select sal from emp1where job = 'CLERK')union (select sal from emp2 where hiredate > '01JAN-83' )union

(select sal+decode(com m,null,0) from emp2,dept wheredname='S ALES' and emp2.deptno=de pt.deptno)union

(select sal from emp4,salgrade where grade=4)union (select sal from emp5) ;GIVING ERROR : Query block has

incorrect no. of result columns.2 3 0 . L ist the highes t p a i d e m p SQ L>Select * from emp where sal =

(select max(sal) from emp) ;231 .List the details of most recently hired emp of dept

30.SQL>Select * from emp where hire date = (select max(hiredate) from empwhere deptno = 30) and deptno = 30;

232.List the highest paid e mp of Chicago joined before the most recentlyhired emp of grade

2.SQL>select emp.*,loc from emp,dept,salgr ade where hiredate <(select max(hiredate) from emp where

hiredate in(select hiredate from emp where hiredate <(select max(hiredate) from emp,salgrade,de pt whereloc =

'CHICAGO' and grade=2 and sal between losal and hisalandemp.de ptno = dept.deptno))) and loc =

'CHICAGO' and grade=2andemp .deptno = dept.deptno and sal between losal and hisalORselect emp.*,loc from

emp,dept where hiredate <(select max(hiredate) from emp where hiredate in(select hiredate from emp where hiredate <(select

max(hiredate) from emp,salgrade,de pt whereloc = 'CHICAGO' and grade=2 and sal between losal and hisal

andemp.deptno = dept.deptno))) and loc = 'CHICAGO' andemp.deptno = dept.deptnoSPE NT 40 MINUTES

ON THE ABOVE QUERY233.Lis t the highest paid emp working under king.SQ L>Select * from emp

where sal = (select max(sal) from e mp wheremgr=( select empno from emp where ename='KING')) ;

END OF BOOK QUERIES 234. List the second highest paid emp SQL>Select * from

emp where sal = (select max(sal) from emp where sal in(sel ect sal from emp where sal < (select max(sal)

from emp))) ;235.Find the oldest date between curre nt date and 01_JAN83.SQL>select greatest(sysda

te,'01-JAN-83') from dual ;

You might also like