24313549-Oracle-SQL-Queries-on-Emp-Table-1-to-235 | Data Management Software | Databases

Oracle Queries

By PenchalaRaju.Yanamala 001. SQL> 002. SQL> 003. SQL> 004. SQL> 005. SQL> 006. SQL> 007. SQL> 008. SQL> 009. SQL> Display all the information of the emp table. Select * from emp ; Display unique jobs from EMP table. SELECT DISTINCT Job FROM EMP GROUP BY Job ; List the details of the emps in asc order of their salaries. SELECT * FROM EMP ORDER BY Sal ASC ; List the details of the emps in asc order of the Deptnos and desc of Jobs. SELECT * FROM EMP ORDER BY Deptno ASC, Job DESC ; Display all the unique job groups in the descending order select unique job from emp order by job desc ; Display all the details of all ‘Mgrs’ select * from emp where job = 'MANAGER' ; List the emps who joined before 1981. select * from emp where hiredate < '01-Jan-1981' ; List the Empno, Ename, Sal, Daily Sal of all Employees in the ASC order of AnnSal. SELECT Empno, Ename, sal, Sal/30 DailySal FROM Emp ORDER BY Sal*12 ; Display the empno , ename, job, hiredate, exp of all Mgrs select empno, ename, sal, months_between(sysdate,hiredate)/12 Exp from emp where job = 'MANAGER' ; List the empno, ename, sal, exp of all emps working for Mgr 7839. select empno, ename, sal, months_between(sysdate,hiredate)/12 Exp from emp B where Mgr = 7839 ; Display the details of the emps whose Comm. Is more than their sal. select * from emp where comm > sal ; List the emps in the asc order of Designations select * from emp order by job ; List the emps along with their exp and daily sal is more than Rs.100

010. SQL>

011. SQL> 012. SQL> 013.

SQL> 014. SQL> 015. SQL>

Select emp.*, months_between(sysdate,hiredate)/12 Exp from emp where sal/30 > 100 ; List the emps who are either ‘CLERK’ or ‘ANALYST’ in the desc order Select * from emp where job in (‘CLERK’,‘ANALYST’) order by job desc ; List the emps who joined on 1May81,31Dec81, 17Dec81, 19Jan80 in asc order of seniority. Select ename,hiredate,months_between(sysdate,hiredate)/12 EXP from emp where hiredate like '01-MAY-81' or hiredate like '31-DEC-81' or hiredate like '17-DEC-81' or hiredate like '19-JAN-80' order by hiredate desc ; List the emps who are working for the deptno 10 or 20 Select * from emp where deptno in (10,20) ; List the emps who are joined in the year 1981 Select * from emp where hiredate like ‘%81’ ; List the emps who are joined in the month of Aug 1980 Select * from emp where hiredate like %AUG-80’ ; List the emps whose annul sal ranging from 22000 and 45000 Select * from emp where sal*12 between 22000 and 45000 ; List the emps those are having five characters in their names. Select * from emp where ename like ‘_____’ ; List the enames those are starting with ‘s’ and with fire characters Select * from emp where ename like ‘S____’ ; List the emps those are having four chars and third char must be ‘r’ Select * from emp where ename like ‘__R_’ ; List the 5 character names starting with ‘s’ and ending with ‘h’ Select * from emp where ename like ‘S___H’ ; List the emps who joined in January Select * from emp where hiredate like ‘%JAN%’ ; List the emps who joined in the month of which second character is ‘a’ Select * from emp where hiredate like ‘__-_A%’ ; List the emps whose sal is 4 digit number ending with zero Select * from emp where sal like ‘___0’ ; List the emps whose names having a character set ‘ll’ together Select * from emp where ename like ‘%LL%’ ;

016. SQL> 017. SQL> 018. SQL> 019. SQL> 020. SQL> 021. SQL> 022. SQL> 023. SQL> 024. SQL> 025. SQL> 026. SQL> 027. SQL>

List the emps of deptno 30 or10 joined in the year 1981 Select * from emp where deptno in(10. ename.’MANAGER’) order by sal . SQL> 032.'RESEARCH') AND EMP.DEPTNO = DEPT.DEPTNO = DEPT.SAL. SQL> 037. List the emps who joined in any year but not belongs to the month of March Select * from emp where hiredate not like ‘%MAR%’ . List all the emps except ‘president’ & ‘Mgr’ in asc order of salaries Select * from emp where job not in (‘PRESIDENT’. List the emps who does not belong to deptno 20 Select * from emp where deptno <> 20 . Select * from emp where deptno=20 and job =’CLERK’ . Display the details of ‘Smith’ Select * from emp where ename = ‘SMITH’ . SQL> 039. DEPT WHERE LOC IN ('NEW YORK'. dname of all the ‘Mgrs’ and ‘Analyst’ working in NEWYORK. SQL> 031. List the emps who are working under ‘Mgr’ Select * from emp where mgr in (select empno from emp where job = ‘MANAGER’) .*.DEPTNO 040.'DALLAS') AND JOB IN ('MANAGER'. ENAME. SELECT EMPNO. SQL> 038. SQL> 036. List the emps who joined in before or after 1981 Select * from emp where hiredate not like '%81' . SQL> List the emps those who joined in 80’s Select * from emp where hiredate like ‘%80’ . SQL> 030.HIREDATE)/12 > 7 AND COMM IS NULL AND EMP.DEPTNO ORDER BY EMP.DEPTNO List the empno.DNAME.30) and hiredate like ’%81’ . List the emps whose empno not starting with digit 78 Select * from emp where empno not like ‘78%’ . DALLAS with an exp more than 7 years without receiving the Comma Asc order of Loc. SQL> 029. Display the location of ‘Smith’ Select loc from emp where ename = ‘SMITH’ . sal.LOC FROM Emp. SQL> . dname FROM EMP. List the total information of emp table along with dname and loc of all the emps working under ‘Accounting’ & ‘Research’ in the asc deptno SELECT EMP. SQL> 035.'ANALYST') AND MONTHS_BETWEEN(SYSDATE. SQL> 033. Dept WHERE Dname IN ('ACCOUNTING'. SQL> 034.028. List all the clerks of deptno 20.

exp. List the empno.EMP.ORDER BY LOC . ename.deptno=dept.deptno=dept.grade from emp. SQL> 043.*. grade. SQL> 045. 041. job of all emps working at CHICAGO or working for ACCOUNTING dept wit ann sal > 28000. DEPT WHERE (LOC = 'CHICAGO' OR DNAME = 'ACCOUNTING') AND SAL*12 > 28000 AND SAL NOT IN(3000.'MANAGER') and sal between losal and hisal .DEPTNO ORDER BY EMP. grade. sal. . dname. Display the total information of the emps along with grades in the asc order Select emp. dname. Select empno. List the details of the depts along with empno. sal.5) and Job in ('ANALYST'. dept. loc.JOB.salgrade where grade in(2.DEPTNO.DEPTNO ASC.3) and sal between losal and hisal Display all grade 4. deptno. but the sal should not be = 3000 or 2800 who doesn’t belongs to the Mgr and whose no is having a digit ‘7’ or ‘8’ in 3rd position in the asc order of deptno and desc order of job. grade from emp. SQL> 046.deptno and sal between losal and hisal List all the information of emps with loc and the grade of all the emps belong to the grade ranges from 2 to 4 working at the dept those are not starting with char set ‘OP’ and not ending with ‘S’ with the design having a char ‘a’ any where joined in the year 81 but not in the month of Mar or Sep and sal not end with ‘00’ in the asc order of grades. grade from emp. months_between(sysdate. List the empno. JOB DESC .20) and emp.deptno and sal between losal and hisal .salgrade where sal between losal and hisal . salgrade where emp. SQL> 047.2800) AND MGR IS NULL AND EMPNO LIKE '__7_' OR EMPNO LIKE '__8_' AND EMP. Select emp. ann sal of emps working for dept 20 or 10.DEPTNO = DEPT. loc. SELECT EMPNO.*. ENAME. sal*12 AnnSal.*.SAL. dept. ename.deptno in(10. sal. loc FROM EMP.salgrade where grade in(4.5 Analyst and Mgr Select emp. salgrade where Grade between 2 and 4 and dname not like ‘OP%’ and dname not like ‘%S’ and Job like ‘%A%’ and (hiredate like ‘%81’ and hiredate not like ‘%MAR%’ and hiredate not like ‘%SEP%’) and sal not like %00 and emp. List all the grade2 and grade 3 emps Select emp. ename. dname.*. SQL> 044.hiredate)/12 Exp from emp. ename or without the emps SQL> 042. grade from emp. dname.

sal > B.deptno=dept. dept. List the emps whose Sal is > the total remuneration of the SALESMAN.SQL> 048. SQL> 055. Note : no rows will be selected. If you choose job=’CLERK’. SQL> 051.dept where Hiredate < 054.ename = 'BLAKE' Using sub-query: select * from emp where sal > (select sal from emp where ename = 'BLAKE') 049. ename. SQL> Select empno. select * from emp where job = (select job from emp where ename = 'ALLEN') List the emps who are senior to King select * from emp where hiredate < (select hiredate from emp where ename = 'KING') List the emps who are senior to their own MGRs select * from emp A where hiredate < (select hiredate from emp B where b.deptno .'SMITH')) and ename not in ('FORD'.Mgr) List the emps of deptno 20 whose jobs are same as deptno 10 Select * from emp where deptno=20 and job in (select job from emp where deptno=10) . Select * from Emp. List the emps whose Jobs are same as MILLER or Sal is more than ALLEN.sal and B. SQL> 053.dept where emp. SQL> . emp B where A.* from emp.* from emp A. List the emps who are Senior to ‘BLAKE’ working at CHICAGO & BOSTON. Select * from Emp where sal > (select SUM(sal) from emp where JOB=’SALESMAN').'SMITH') Order By sal Desc . SQL> 056. Select distinct * from Emp where sal in (select sal from emp where ename in ('FORD'. Select * from Emp where job = (select job from emp where ename=’MILLER’) OR Sal > (select sal from emp where ename ='ALLEN') . one record will be fetched. List the details of the emps whose salaries more than the employee BLAKE Using self-join: select A. SQL> 052. SQL> List the details of the emps whose job is same as ALLEN. List the emps whose Sal is same as FORD or SMITH in desc order of Sal.Empno = A. SQL> 050.

SQL> 060. Two record will be fetched. If you choose ename=’TURNER’. SQL> List the emps of Grade 3.salgrade where grade=2 and sal between losal and hisal) OR sal in (select sal from Emp.dept. ’SMITH’ is the senior most in the emp table.salgrade.4) AND dname in ('ACCOUNTING'. Find the details of highest paid employee. SQL> 061.deptno = dept. e) Any Grade 2&3 employee working for SALES dept or OPERATIONS dept joined in 89. SQL> . Note : no rows will be selected.'RESEARCH') and Sal > (select sal from emp where ename='ALLEN') and Hiredate < (select hiredate from emp where ename='SMITH') and emp.'OPERATIONS') and hiredate like '%89' and sal between losal and hisal and emp. Select * from Emp where job in (select distinct job from emp where ename in ('ALLEN'.'SMITH').deptno) List the jobs of Deptno 10 those are not found in dept 20.salgrade where grade in(3. Select Max(sal) from emp . SQL> 063. d) Any Grade 2 employees of Emp4 table. b) ¾ Sal of any Mgr of Emp2 table.(select hiredate from emp where ename='BLAKE') AND loc in ('CHICAGO'. c) The Sal of any sales person with exp of 5 yrs belongs to the sales dept of emp3 table.deptno . 057.deptno and sal between losal and hisal.4 belongs to the dept ACCOUNTING and RESEARCH whose sal is more than ALLEN and exp more than SMITH in the asc order of Exp. SQL> 062.'SMITH')) and ename not in ('ALLEN'. Select * from emp where deptno = 10 and job not in (select job from emp where deptno=20) List the emps of Emp1 who are not found in deptno 20 Select * from emp where ename not in (select ename from emp where deptno=20) Find the highest Sal of the Emp table. SQL> 059.deptno = dept. Select * from emp where sal in (select sal from emp1) OR sal in (select sal*3 from Emp2 where job='MANAGER') OR sal in (select sal from Emp3 where months_between(sysdate.deptno=dept. List the emps whose jobs same as ALLEN Or SMITH.'BOSTON') and emp.3) and dname in ('SALES'. Select * from Emp. Write a Query to display the details of emps whose Sal is same as of a) Employee Sal of Emp1 table.dept where grade in(2. 058. Because.hiredate)/12 > 5) OR sal in (select sal from Emp4. Select * from emp where sal = (select Max(sal) from emp) .

salgrade where hiredate = (select max(hiredate) from emp where mgr= (select empno from emp where ename = 'KING')) and grade > 3 and sal between losal and hisal Find the total sal given to the ‘MGR’ select sum(sal) from emp where job = 'MANAGER' Find the total annual sal to distribute job wise in the year 81 select Job. sum(sal) from emp.deptno) and Mgr = (select empno from emp where ename='KING') And emp.deptno = dept.sum(sal*12) from emp GROUP BY JOB .deptno and sal between losal and hisal . List the emps who are senior to most recently hired emp who is working under Mgr KING Select * from emp where hiredate < (Select max(hiredate) from emp) and mgr=(select empno from emp where ename=’KING’) . SQL> 071.064. Display the details of most senior employee belongs to 1981.deptno ) . List the details of emp belongs to New York with the Grade 3 to 5 except ‘PRESIDENT’ whose sal > the highest paid emp of CHICAGO in Group where there is ‘MANAGER’ & ‘ANALYST’ not working for Mgr KING Select * from emp.'ANALYST') and emp. select grade. List the most recently hired emp of grade 3 belongs to the Loc CHICAGO Select * from emp. SQL> 072. List the most senior emp working under KING and Grade is more than 3.salgrade where loc='NEW YORK' and Grade in (3. SQL> 073. SQL> 066. SQL> 070. Select * from emp where sal = (select Max(sal) from emp. SQL> . select emp.salgrade where 067.4. SQL> Find the highest paid employee of sales dept. SQL> 068. select * from emp where hiredate like '%81' and job = (select job from emp where hiredate= (select min(hiredate) from emp where hiredate like '%81')) .deptno = dept.dept where loc=’CHICAGO’ and hiredate = (Select max(hiredate) from emp).5) and job <> 'PRESIDENT' and Sal > (select Max(sal) from emp. Display the total sal of emps belong to Grade 3. select * from emp where hiredate = (select min(hiredate) from emp where hiredate like '%81') . SQL> 065. SQL> 069. List the emps who joined in 81 with job same as the most senior person of year 81.* from emp.deptno = dept.dept where loc='CHICAGO' and Job not in ('MANAGER'.dept where dname=’SALES’ and emp.dept.

deptno = emp.salgrade where dept. Display the number of emps for each job group deptno wise select dname.job having count(empno) >= 2 . grade.2) > 3000 .dept where dept.2) incrsal from emp where SAL+(SAL*. no of emps where atleast two emps are ‘CLERKS’ select dname. Display dname. select dname.job.deptno = emp. Display the grade.deptno group by dname.deptno = emp. of emps working for those Mgrs in the asc Mgrno. Display the emps whose Mgr name is Jones Select * from emp where mgr = (select empno from emp where ename = ‘JONES’) . 074.*. SQL> 083. List the emps whose salary is more than 3000 after giving 20% increment Select EMP. List the Mgr no & no. List the emps in dept 20 whose sal is > the avg sal of deptno 10 emps. List the details of the dept where the max no of emps are working select dname.max(sal) from emp.sal between losal and hisal group by grade .grade.grade having count('CLERK') >= 2 .dept. SQL> 076. SQL> 080. SQL> Display the avg salaries of all CLERKS select avg(sal) from emp where job = 'CLERK' .deptno and sal between losal and hisal group by grade . number of emps.deptno group by dname having count(empno) = (select max(count(empno)) from emp group by deptno) . count(empno) from emp.dept where dept. count(empno). SQL> 075.SAL+(SAL*. select grade. SQL> 081.deptno = emp. count(empno) from emp.deptno and sal between losal and hisal group by dname. List the dept details where at least two emps are working. SQL> 079. SQL> . max sal of each grade. select * from emp where sal > (select avg(sal) from emp where deptno=10) and deptno=20 .deptno group by dname.dept where dept.deptno = emp.count(empno) from emp.job . SQL> 082. 077.count(*) from emp group by mgr order by mgr asc . SQL> 078.salgrade where dept.dept. count(empno) from emp. select mgr.

List the emps who are not working in sales dept Select emp.deptno in (select distinct deptno from emp group by emp.*.deptno = dept. SQL> 090.30) and grade <> 4 and hiredate in (select hiredate from emp where hiredate < '31-DEC-82') and sal between losal and hisal List the name. Manager. dname. select A. sal. List the name and salary of FORD if his salary is equal to hisal of his Grade select ename.084. SQL> 088.deptno . grade and dname except ‘CLERK’s and sort on the basis of highest salary. SQL> 091. salgrade where ename = 'FORD' and sal between losal and hisal) List the name. salgrade where emp. emp B where A. dept where emp. List the emps whose mgr name is ‘JONES’ and also list their manager name select A. dept.deptno . select ename. ename.dept where job = 'MANAGER' and emp.*. dept.deptno=dept. sal & comm. List the emps name. job. For those whose salary is between 2000 and 5000 while loc is CHICAGO Select ename.deptno = dept. sal from emp where ename = 'FORD' and sal = (select hisal from emp. dname. comm from emp. dept where Dname <> ‘SALES’ and emp. dname. loc for those who are working as a ‘MGRs’ select empno.salgrade where deptno in (10. List the emps name.deptno . Grade dept wise.mgr=B. dname. dname from emp.ename='JONES' . job.empno and b. grade. hiredate from emp. sal.deptno = dept.deptno = dept.* from emp A. sal.sal > B. job.*.mgr = B. SQL> 089.sal . job.ename from emp A. Select ename. grade from emp. SQL> 085.deptno and sal between losal and hisal and emp. SQL> 087. List the emps whose salary is > his Manager’s salary. dname from emp. List the grade. dept.deptno) . SQL> List the emps with their dept names. Mgr. SQL> 092. loc from emp. salary. employee name for the deptno 10 or deptno 30 but salgrade is not 4 while they joined the company before ’31-DEC-82’ select grade. SQL> 093.deptno . B.ename. dname. dept where sal between 2000 and 5000 and loc = 'CHICAGO' and emp. salgrade 086. dname from emp. job. Select emp.empno and A. salary. job.emp B where A. SQL> .

A. emp B where ((A.deptno in (select distinct deptno from emp group by emp. List the names of depts. sal.ename. sal.sal and A.where job <> 'CLERK' and dept. List the emps whose sal < his Manager but more than other Manager Select distinct A. job and Manager who are without Manager.comm from emp A. Select ename. SQL> 099.deptno and emp.empno and A. List the managers whose salary is more than his emps avg sal. dept where emp. Select dname.* from emp A. emp C where A. job. OF MAX SAL AND MIN SAL select * from emp where sal = (select (max(sal)+min(sal))/2 from emp) . SQL> 095.deptno = emp.deptno = dept. SAL Select ename. Select ename. SQL> .* from emp A. A. List the name. sal from emp where sal = (select avg(sal) from emp) . Select distinct A. For those emps whose net pay is > or = any other employee salary of the company.mgr and A.sal*1. mgr from emp where mgr is NULL . Select deptno. Where at least 3 emps are working in each dept. 094. List the emps whose salary is equal to average of maximum and minimum.empno = B.sal*1.sal + A. Select distinct A. emp B. TO RETRIEVE SAL WHICH IS = TO AVG.mgr = B. emp B where A.2) + (A. SQL> 102. count(deptno) from emp group by deptno having count(deptno) > 3 . dname from emp.deptno) > 3 . SQL> List the emps name. count(emp. SQL> 101.deptno and sal between losal and hisal order by sal desc . TO RETRIEVE SAL WHICH IS = TO AVG. job.sal < B.Empno and job = 'MANAGER') . 097.sal.deptno) from emp. job.mgr not in (select empno from emp where empno <> B. List the names of emps who are getting the highest salary dept wise. ??? List the employee names and his annual salary dept wise. select ename. comm.deptno group by dname having count(emp.6 + 80)) >= (select avg(sal) from emp) .deptno=dept.2) -(A. dept where 096.sal and A. sal*12 from emp.deptno) and sal in (select max(sal) from emp group by deptno) . SQL> 098. SQL> 100. dname.sal*1.sal) from emp group by B. SQL> List the no of emps in each dept where the number is more than 3.sal > (select avg(B.dept where emp.Mgr) .sal > C.

OR Select deptno. months_between(…)/12 giving o/p greater than 100. hiredate. SQL> List the name.hiredate)/12 Retirement_Date from emp where months_between('31-DEC-89'.job = 'MANAGER' .hiredate)/12 Exp from emp where months_between(sysdate. select emp. List the records from emp whose deptno is not in dept HOW CAN IT BE POSSIBLE??? [A REFERENCE KEY VALUE WITHOUT A PRIMARY KEY VALUE. ename.JOB from emp A. sal. Select * from emp where mod(sal. List the Mgrs who are not working under ‘PRESIDENT’ but are working under other Manager.sal . SQL> List those emps whose sal is odd value. select * from emp where rownum < 6 order by sal asc Find out the no of emps whose salary is > their Manager salary. SQL> 104. SQL> 108. List the emps who joined in the month of ‘DEC’ Select * from emp where hiredate like ‘%DEC%’ . sal+sal*1. sal*12 from emp group by deptno.emp.2) <> 0 . select A.hiredate) / 12 > 20 . List the enames who are retiring after ’31-DEC-89’ the max job period is 20Y. select count(A.Mgr = B. ename. ABOVE QUERY IS WORKING BUT BELOW QUERY IS NOT. 103.Mgr = B. comm. And net pay is more than any other employee. select empno. 106. emp B where A.hiredate)/12 > 20 order by hiredate .2+800 Net from emp where sal = (select max(sal) from emp) . comm.deptno .*. emp B where A. List the emps whose sal contain 3 digits Select * from emp where length(sal) = 3 .ENAME.sal and A. SQL> 105. sal. SQL> . A.empno . SQL> 111. SQL> Find out least 5 earners of the company.deptno = dept. months_between(sysdate.ename. SQL> 110.sal > B.deptno in (select deptno from emp group by deptno) and emp.ename <> 'PRESIDENT' AND A. months_between('31-DEC-89'.empno and B. IN BELOW QUERY I GAVE DATE() IN PLACE OF SYSDATE.] select * from emp where deptno not in (select deptno from dept) 107. 109. Select empno.empno) from emp A. sysdate.

8 Which is a wrong O/P. dept where emp. List the emps whose 10% of sal is equal to year of Joining select ename.length(sal)-1.deptno having Count(empno) in (select length(dname) from dept group by dname) group by emp. SQL> .deptno 114.sal . hiredate from emp where substr(hiredate.1 like substr(hiredate. O/P : Reserch . length(dname) Len from dept where deptno = (select emp.2) = deptno or substr(sal. select ename. List first 50% of chars of ename in lower case and remaining are upper case.2) = deptno .deptno from emp. dept where emp.2) = deptno or substr(sal. select ename. List the emps whose deptno is available in his salary.1. SQL> 117. lower(substr(ename. deptno from emp where substr(sal. sal * . upper(substr(ename. count(empno) from emp.length(sal)-2. sal.length(hiredate)-1. dept where emp. select dname. hiredate from emp where sal * . length(dname) Len from dept where deptno = (select emp.length(ename)/2)).2) = substr(sal. select ename. select dname.deptno) . List the dname whose no of emps is = to no of chars in the dname. I HAD TO CHANGE ONE SALES DEPT(DEPTNO 30) EMP TO SOME OTHER DEPT – SO THAT THE NO OF CHARS IN SALES DEPT(5) IS = NO OF EMPS OF THAT DEPT.deptno) .(length(ename)/2)+1. SQL> 113. THIS QUERY WILL WORK AFTER MODIFING EMP TABLE.deptno = dept. TO GET THE OUTPUT. [AT PRESENT THERE ARE 6 EMPS] IF U DON’T CHANGE THE ABOVE. SQL> List the emps whose names contains ‘A’ select ename from emp where ename like '%A%' . List the emps whose first 2 chars from hiredate = last 2 chars of salary.1.2) .deptno = dept.112.1. SQL> 115. select dname.length(ename))) from emp .deptno = dept.deptno having Count(empno) in (select length(dname) from dept group by dname) group by emp.2) . OF EMPS = NO OF CHARS IN THE DNAME. U GET THE WRONG O/P FOR THE SAME.deptno from emp. SQL> 116. AT PRESET THERE ARE NO SUCH DNAME WHERE NO.length(sal)-1. sal.length(sal)-3.

List the name of dept where highest no of emps are working select dname. dept where emp. length(dname) Len from dept where deptno IN (select emp. SQL> List the emps who are working as managers select * from emp where empno in (select mgr from emp) . emp. 120. SQL> 124.deptno) . NO ROWS SELECTED 119.deptno having Count(empno) in (select count(empno) from emp group by deptno) group by emp. Count the no of emps who are working as ‘Managers’ (using set option) Select * from emp where empno in (select empno from emp) Union (select Mgr from emp) GIVING ERROR : ‘Query block has incorrect number of result columns’ List the emps who joined in the company on the same date select * from emp where hiredate in (select hiredate from emp having count(hiredate) > 1 group by hiredate) . List the details of the emps whose grade is equal to one tenth of sales dept. select * from emp. dname . count(empno) from emp.118. 122.deptno = dept. SQL> List the dname. select dname. length(dname) from dept . SQL> .deptno having count(empno) = (select max(count(empno)) from emp group by deptno) group by emp.deptno.deptno from emp. dept where emp. salgrade where grade = deptno/10 and deptno = (select deptno from dept where dname='SALES') and sal between losal and hisal . SQL> 121.deptno. SQL> group by dname .deptno = dept. select * from emp where hiredate in (select hiredate from emp where hiredate > (select hiredate from emp where hiredate like '14-%')) . count of emps List the emps those who joined in company before 15th of the month. SQL> 123. no of chars of which is no of emp’s in any other dept ??? select dname. O/P : Dname.

Produce the following output from EMP EMPLOYEE ---------------SMITH(clerk) ALLEN(salesman) select ename || '(' || lower(job) ||')' EMPLOYEE from emp .'On target'. List the emps with hiredate in format June 4. 'just salary'.OR select * from emp. salgrade where grade = deptno/10 and sal between losal and hisal .') from emp . dept.deptno) and emp2.deptno in (select deptno from emp group by emp. 126. sal + sal * 0.deptno.(sal>1500). SQL> 129. to_char(hiredate.'Month DD. List the ename and sal is increased by 15% and expressed as no of dollars. count(empno) from emp2.1988.deptno. Print a list of emp’s listing ‘just salary’ if salary is more than 1500. SQL> List the name of the dept where more than avg. (sal + sal * 0. dept where emp2.deptno group by dept. SQL> select ename. (sal + sal * 0. List the managers name who is having max no of emps working under him select ename from emp where empno = (select mgr from emp having count(empno) = (select max(count(empno)) from emp group by mgr) group by mgr) . decode(sal. 1500. Produce the output of EMP table ‘EMP_AND_JOB’ for ename and job select ename || '_AND_' || job from emp . SQL> 130.'Below 1500'. no of emps are working select dname.15). SQL> 127. 132. MISSING RIGHT PARENTHESIS.YYYY. 128. ‘On target’ if salary is 1500 and ‘Below 1500’ if salary is less than 1500.deptno = dept. decode(sal.15. dname having count(empno) >= (select count(deptno) from dept) . Write a query to return the day of the week for any date entered in . sal.15)/34) NewSal from emp . SQL> 131. 125.(sal<1500).sal) from emp . SQL> select ename. select ename.

sal . to_char(substr(to_char(sal). List the emps who are working as managers using co-related subquery Using Sub Query : Select * from emp where empno in(select mgr from emp) . SQL> 134. Count the no of characters without considering spaces for each name. 133. emp B where A. 'day') from dual Wrote a query to calculate the length of service of any employee with the company. ‘12/34’.Mgr=B. SQL> 137. sal from emp where to_char(substr(to_char(sal). Find out the emps who are getting decimal value in their sal without using like operator. Use the following values to test your solution.SQL> format ‘DD-MM-YY’ select to_char(hiredate.1)) ='. their hiredate and the first pay date.1)) from emp . SQL> 136. Print the expression ‘YES’ if valid.' 138. SQL> 135. SQL> List those emps whose salary contains first four digit of their deptno. Print the details of all the emps who are sub-ordinates to BLAKE. verify that the first and last two characters are numbers and that the middle character is ‘/’. select * from emp where mgr = (select empno from emp where ename='BLAKE') . Those hired after 15th are paid on the first Friday of the following month. select distinct B. Select ename.3.* from emp A. SQL> 141.empno and A. ‘01/la’. . ‘99/98’ Emps hired on or before 15th of any month are paid on the last Friday of that month. SQL> Select ename. ‘NO’ if not valid. Print a list of emps. ??? ?????????? salary contains first four digit of their deptno ????? List those managers who are getting less than his emps salary. length(ename) from emp . sal. Sort on hiredate.sal > B. use DEFINE to avoid repetitive typing of functions DEFINE ???? Give a string of format ‘NN/NN’. SQL> 140. SQL> 139.-3. OR select to_char(sysdate. 'day') from emp . Select ename.

count(empno). SQL> 144.* from emp A. sum(decode(comm. List the employee name. SQL> 145. job.null.*. OR Select job. sal*12 AnnSal. sort the output by salary. B. Use the variable in a statement which finds all emps who can earn 30000 a year or more. sum(decode(comm. 143. ??? List the emps who are drawing less than 1000. Find out the job that was filled in the first half of 1983 and same job that was filled during the same period of 1984. dept. SQL> Check whether all the emps numbers are indeed unique. select distinct A. SQL> . SQL> 147.null. select emp. annual sal.avg(sal).ename='JONES' . sal*12 Ann_Sal from emp where sal*12 >= 30000 .ename from emp A. Using Co-Releated Sub Query : Select distinct A. OR Select job. emp B where A. sum(sal) from emp group by job . and grade who earn 36000 a year or who are not CLERKS. SQL> 149. emp B where A. Select job.empno in(select B. 146. dname.Using Co-Releated Query : Select distinct A. SQL> List the emps whose Mgr name is ‘JONES’ and also with his Manager Name.* from emp A. salgrade where sal*12 > 36000 and job <> 'CLERK' and sal between losal and hisal and dept.mgr from emp) 142. Remember salesman earn commission. Select * from emp where sal < 1000 order by sal . Find out how many managers are there in the company.deptno = emp.deptno. Define a variable representing the expression used to calculate on emps total annual remuneration.mgr = (select empno from emp where ename='JONES') and B. SQL> 148. Find avg sal and avg total remuneration for each job type. job.deptno . avg(sal).null. grade from emp.0)+sal) from emp group by job . avg(decode(comm. emp.0)+sal) from emp group by job . emp B where A. deptno.empno =B.Mgr .*. Select ename. Select count(*) from emp where empno in(select mgr from emp) . dept name.0)+sal).

SQL> 154.empno. SQL> 153.empno. SQL> 151.mgr from emp A. deptno from emp where sal in (select sal from emp where sal > (select avg(sal) from emp . select A. A. A.empno from emp B where ename='KING') . Find out all the emps who earn highest sal in each job type. SQL> 155. sal and deptno for each emp who earns a sal greater than the avg for their dept order by deptno 152. emp B where A. emp B where A.mgr = B.empno from emp A. Find out the most recently hired emps in each dept order by hiredate select * from emp where hiredate in (select max(hiredate) from emp group by job) order by hiredate desc .ename. SQL> Find out the emps who joined in the company before their managers.mgr = B.hiredate < B.empno . emp B where A. A.hiredate . B. B. Sort in des order of sal select * from emp where sal in (select max(sal) from emp group by job) order by sal desc . sal. HOW TO RETRIEVE KING’S INFO select * from emp where empno in (select distinct A.empno and A.hiredate. Find all the emps who earn minimum sal for each job wise in asc order of sal select * from emp where sal in (select min(sal) from emp group by job) order by sal .mgr = B. List the emp name. ERRRO : Query Block has incorrect number of result columns.empno) union (select B. SQL> select ename.empno.select job from emp where hiredate in (select hiredate from emp where hiredate > '01-JUL-82') and hiredate in (select hiredate from emp where hiredate > '01-JUL-84') NO ROWS SELECTED 150. A.ename from emp A. List all the emps by name and number along with their manager’s name and number also list KING who has no ‘Manager’ select distinct A.mgr.

null. job. job.null. name. sal from emp where deptno <> 10 and job in (select job from emp where deptno=10) or sal in (select sal from emp where deptno=10) .0). sal from emp where deptno <> 10 and job in (select job from emp where deptno=10) and sal in (select sal from emp where deptno=10) . deptno from emp where empno = (select empno from emp where sal+decode(comm.0) 160. SO GIVE : select ename. SQL> 157. sal+decode(comm. 161. sal.null. job. List the no of emps and avg salary within each dept for each job. job and salary of the emps who are not belonging to the dept 10 but who have the same job and salary as the emps of dept 10.group by deptno) group by deptno) order by deptno NOT A GROUP BY EXPRESSION 156.0) in (select sal+decode(comm. salary and sal+comm. SQL> List the deptno where there are no emps select deptno. select ename. Of the emps who earn the second highest earnings (sal+comm) select ename. sal+comm.0)) from emp)))) . Find the max avg salary drawn for each job except for ‘PRESIDENT’ select job. Select ename. NO SUCH RECORDS. dname from dept where deptno not in (select deptno from emp) .null. job.null. Find the name and job of the emps who earn Max salary and Commission. select ename.null.0) in (select sal+decode(comm. job.0) from emp where sal+decode(comm. job. sal. List the name.null.0). count(empno). sal.0)) from emp where sal+decode(comm. deptno from emp where sal+comm = (select max(sal+decode(comm.0) < (select max(sal+decode(comm.null. job.null. job . SQL> List the deptno. avg(sal) from emp group by deptno. avg(sal) from emp where job <> 'PRESIDENT' group by job .null. deptno from emp where sal = (select max(sal) from emp where sal in (select sal from emp where sal < (select max(sal) from emp))) .0) = (select max(sal+decode(comm. sal+decode(comm.0)) from emp where sal+decode(comm. job. sal. max(sal). SQL> 158 SQL> 159. SQL> . comm from emp where sal=(select max(sal) from emp) or comm=(select max(comm) from emp) .null. Select ename. select deptno.

null. Of the salesman select ename.job from emp. avg(sal) from emp having avg(sal) = (select min(avg(sal)) from emp having avg(sal) in (select avg(sal) from emp group by deptno) group by deptno) group by deptno . sal and comm. Display the details of BLAKE. SQL> 169.null. sal from emp where sal >= (select max(avg(sal)) from emp group by deptno) . dept where emp. B.sal from emp A.deptno = (select deptno from emp having count(deptno) = 1 group by deptno) . deptno from emp order by job. List the empno.sal . sal of the emps in the department with the highest avg sal. SQL> 171. 164.0) < (select max(sal+decode(comm. job. Display the unique dept of emps. List out the name. comm From emp . To get the answer enter a new record with deptno as 40. Select * from emp where ename = ‘BLAKE’ . deptno from emp where job = 'SALESMAN' List the deptno and their avg salaries for dept with the avg salary less than the avg for all departments.ename. job. job.sal. of emps Select empno. empno desc . select * from emp where deptno = (select deptno from emp having count(deptno) = 1 group by deptno). salary and sal+comm. ename select empno. comm. sal. sal.from emp where sal+decode(comm. SQL> . job. SQL> 167.sal > B. List out the names and salaries of the emps along with their manager names and salaries for those emps who earn more salary than their manager. SQL> NO ROWS SELECTED List the deptno. select deptno. List the details of the emps in the asc order of salary. SQL> 165. emp B where A. SQL> 166.0)) from emp))) 162. job. name. ename.ename. 170. SQL> Display the unique dept with jobs. SQL> 168. select A. SQL> 163. B. List the dept in asc order of job and the desc order of emps print empno.empno and A. select ename. sal.mgr = B. Select * from emp order by sal . A. select dname.

List the emps Empno. SQL> 173. sal/30 DailySal from emp where job = ‘SALESMAN’ order by sal . List all emps joined on 1 May 81. sal*.sal for all emp joined before 1 apr 81 Select Empno. List the emps whose salaries are less than 3500. Ename. Ename.sal.16)-80) NetSal from emp order by sal . Select empno. sysdate. SQL> Giving wrong output. current date & exp in the asc order of exp. PF. gross.sal*.3 TA.hiredate)/12 Exp from emp order by hiredate . SQL> 174.hiredate from emp where hiredate < '01APR-81' 177.sal*. SQL> 179.(sal*. SQL> 181. 180. SQL> 175. 80 IT.12 PF. sal*. deptno of dept 10 emps in the asc order of sal.2 .hiredate)/12 > 10 . ename.sal.sal. SQL> 176. List the emps whose exp is more than 10 years. ename. SQL> 178. List the empno. sal+sal*1. select * from emp where months_between(sysdate.16)-80 NetDeductions. Select * from emp where sal < 3500 . Select empno. LIC. sal*12 AnnSal. ename. Ename. Select * from emp where hiredate = ’01-MAY-81’ .sal. (sal+sal*1. SQL> List all CLERKs Select * from emp where job = ‘CLERK’ . ename.4 DA. List the empno. ename. deptno from emp where deptno = 10 order by sal . DA 40%. List empno. net allowances and net sal in the asc order of net sal.172. List the emps whose ann sal is < 25000 in the asc order of salaries Select * from emp where sal*12 < 25000 order by sal . ename.2 NetAllowances. select empno.hiredate from emp where hiredate in ( select hiredate from emp where hiredate > '01-APR-81') .04 LIC. Select Empno.sal*. List the empno.sal. (sal*. HRA 50%. hiredate.2 Gross. ann sal. months_between(sysdate.sal TA 30%. ename. Select empno. net deductions. ename. daily sal of all salesman in the asc ann sal. SQL> . sal*1. hiredate.5 HRA.

17 nov 81. List the names start with ‘M’ Select ename from emp where ename like 'M%' List the emps who joined in the year 81 . '17-NOV-81'. Select ename from emp having length(ename) = 4 group by ename . Select * from emp where job = ‘MANAGER’ . select * from emp where hiredate in ('01-MAY-81'. List the emps whose ann sal ranging from 23000 to 40000. SQL> 192. SQL> 187. GIVE ONE MORE ‘_’ IN ENAME. SQL> 186. Select * from emp where Mgr in (7369. SQL> List the emps who joined in the second half of 82. Select ename from emp where ename like '____H' . SQL> 193. 189. 7654. SQL> 190. List the emps who joined in the following dates : 1 may 81. '30_DEC-81') . 7900. SQL> NO ROWS SELECTED List all the 4 chars emps. THERE IS NO SUCH EMPs. THERE IS NO SUCH EMPNOs 188. List the emps who are either CLERKs or MANAGERs. Select * from emp where hiredate in (select hiredate from emp where hiredate > '30-JUN-82') . 7654. SQL> List the emps who joined in year 81. SQL> 183. Select * from emp where job = ‘MANAGER’ or job = ‘CLERK’. SQL> 184.182. 191. THERE IS NO SUCH HIREDATES 185. 30 dec 81. List the emps working under the Mgrs 7369. select * from emp where hiredate like '%81' . NO ROWS WILL BE SELECTED. List the emps names starting with ‘M’ with 5 chars Select ename from emp where ename like ‘M____’ . 7900) . Select * from emp where hiredate > '30-JUN-82'. 7890. 7890. NO ROWS WILL BE SELECTED. SQL> List the emps who are working as Mgrs. List the emps names end with ‘H’ all together 5 chars. Select * from emp where sal*12 between 23000 and 40000 . NO ROWS WILL BE SELECTED.

hiredate)/12 Exp from emp where mgr like '7%' and mgr not like '%9%' and hiredate < (select '01-Jan-83' from dual) . List the emps whose salary is 4 digit no. List the empno. List the emps who joined in the month of jan Select * from emp where hiredate like ‘%JAN%’ . SQL> 199. sal.SQL> 194. SQL> 195. SQL> Select * from emp where hiredate like ‘%81’ .*. SQL> 202. SQL> 196. SQL> 197. months_between(sysdate.hiredate)/12 > 8 . List the Mgrs of dept 10 or 20. List the emps who are working as either mgr or analyst with sal ranging from 2000 and 5000 and without comm. SQL> 198. List the emps joined in Jan with salary ranging from 1500 to 4000. CHECK OUTPUT. List the emps who joined in 80’s. SQL> 206.. List the emps who joined in the month having a char ‘a’ Select * from emp where hiredate like ‘%A% . select emp. ename. List the emps along with the exp of those working under the mgr whose no is starting with 7 but should not have a digit 9 joined before 1983. List the emps who are either clerks with an exp more than 8y Select * from emp where job = ‘CLERK’ or Months_between(sysdate. List the emps whose sal is ending with 00. SQL> 203.20) order by job desc . job of emps with the ann sal < 34000 but receiving some comm. 20 or 30 in des order select distinct job from emp where deptno in (10. 205.’ List the emps who joined in the month having a second char is ‘A’ Select * from emp where hiredate like ‘%-_A%’ . List the unique jobs of depts..'ANALYST') and sal between 2000 and 5000 and comm is null . DATE IS GIVING WRONG RESULT. Select * from emp where hiredate like ‘%8_’ . select * from emp where JOB IN ('MANAGER'. select * from emp where deptno in (10.20) and job = 'MANAGER' . SQL> 200. Select * from emp where hiredate like ‘%JAN%’ and Sal between 1500 and 4000 . Select * from emp where sal like ‘____’ . Which should not be > sal and designation . SQL> 204. SQL> 201. Select * from emp where sal like ‘%00’ .

SQL> 210. > 200 with exp >= 7y and sal < 2500 but not belongs to the month SEP or NOV working under the Mgr whose no is not having digits either 9 or 0 in the asc dept & desc dept. ename. APR & SEP and working for mgrs & no is not ending with 88 or 56.deptno .deptno . job from emp where sal*12 < 34000 and comm is not null and comm < sal and job = 'SALESMAN' and deptno=30 .4) and months_between(sysdate. ename.deptno. SQL> .dept where loc = ‘CHICAGO’ and Dept. but not belongs to months of MAR. ename.. job.hiredate)/12 >= 7 and sal < 2500 and hiredate not in (select hiredate from emp where hiredate like '%SEP%' or hiredate like '%NOV%') and mgr in (select empno from emp where empno not like '%9%' or empno like '%0%')) order by deptno desc NO ROWS SELECTED List the details of emps working at CHICAGO.ename.dept.hiredate)/12 Exp from emp where (deptno in (10. SQL> 209. deptno.loc from emp. select * from emp where deptno in (10.20) and job IN ('CLERK'. Select * from emp. sal. sal.deptno = emp. ename. months_between(sysdate. List the empno. SQL> 208.SQL> should be salesman working for dept 30. deptno & exp of all emps belongs to dept 10 or 20 with an exp 6 to 10 yrs working under some mgr without comm.dept where Dept. 207. [???] select empno. select empno. with a job not ending with ‘MAN’ but sal > 850 or the emps working for dept 30 with a job having a char ‘A’ irrespective of the position with comm. job. loc of all emps Select empno. List the empno.deptno.20) and (months_between(sysdate.hiredate)/12 > 8 and hiredate not in (select hiredate from emp where hiredate like '%MAR%' or hiredate like '%APR%' or hiredate like '%SEP%') and mgr is not null and empno not in (select empno from emp where empno like '%88' or empno like '%56') .'ANALYST') and length(sal) in (3.hiredate)/12 between 6 and 10) and mgr is not null and comm is null and job not like '%MAN' and sal > 850) or (deptno = 30 and job like '%A%' and comm > 200 and months_between(sysdate. sal.deptno = emp. List the emps who are working for dept 10 or 20 with desigs as CLERK or analyst with a sal is either 3 or 4 digits with an exp > 8y.

deptno = emp. loc from emp.deptno and sal between losal and hisal . Select empno. salgrade where grade = 3 and dname in ('RESEARCH'. 10 or 20. dname of all depts.'DALLAS') and sal between 2000 and 5000 and hiredate like '%81' and Emp. Joined after 1987 and whose names should not be either miller or allen. new york with sal ranging from 2000 to 5000 joined in 81.deptno = dept. job from emp.deptno . loc of all emps working at CHICAGO.deptno and sal between losal and hisal . loc from emp.'ALLEN') and Emp. ename. sal. SQL> 217.deptno . salgrade where grade = 3 and dname in ('RESEARCH'. loc.* from emp.'SALES') and hiredate in (select hiredate from emp where hiredate < '31-DEC-87') and ename not in ('MILLER'.hiredate)/12 > 6 and Emp. 213. SQL> 214.deptno = dept.'OPERATIONS') and hiredate in (select hiredate from emp where hiredate > '31-DEC-87') and ename not in ('MILLER'.211. loc. grade from emp. job from emp. List the grade 3 emps of research & operations depts.'DALLAS') and grade in (3. SQL> .dept where Deptno in (10. NO SUCH RECORDS. grade. sal.3) and sal between losal and hisal . salgrade where job = 'ACCOUNTING' or Loc in ('chicago'.loc from emp. ename.'ALLEN') and Emp. salgrade Where sal between losal and hisal .'DALLAS') and Months_between(sysdate.deptno = dept. List the empno. dept.5) and months_between(sysdate. List the empno. SO GIVE : Select ename. Select ename. Select empno.deptno . dept where Loc in ('CHICAGO'.ename. Select empno.hiredate)/12 > 6 and Emp.4. ename. dept.'OPERATIONS'. SQL> 215. SQL> List the empno. sal.20) and Dept. dname. Select ename. sal.salgrade where Job = ‘CHICAGO’ and grade in (2.dname. dname. grade from emp. loc.deptno and sal between losal and hisal . SQL> 212. List the grade 2&3 emp of Chicago Select emp. loc. grade of all emps. List the emps along with loc of those who belongs to Dallas. SQL> 216. List the emps with loc & grade of accounting dept or the locs Dallas or Chicago with the grades 3 to 5 & exp > 6y. DALLAS with an exp> 6yrs.deptno = dept.deptno = dept. dept where Loc in ('NEW YORK'. Select ename. dept. grade.

sal > (select sal from emp where B. SQL> List the Mgrs who are senior to king & who are junior to smith. Select * from emp where job = 'MANAGER' and hiredate < (select hiredate from emp where ename = 'KING') and hiredate > (select hiredate from emp where ename = 'SMITH') . List the emps whose sal > blake’s Select A.* from emp A.hiredate from emp where empno = B.218.* from emp A. dept. Select * from emp where hiredate < (select hiredate from emp where ename = 'MILLER') . salgrade Where ename = 'MILLER' and sal between losal and hisal) and sal between losal and hisal 225. SQL> 219. SQL> 223.empno and A. SQL> 224.deptno = (select deptno from emp where ename='KING') and emp. salgrade Where emp. 221. SQL> . List the empno. SQL> 220. Select emp. List the emps who are senior to their own mgr. sal. SQL> List the emps whose job is same as smith.ename = 'ALLEN' and emp. Select * from emp where job = (select job from emp where ename=’SMITH’) .hiredate < (select B. List the emps who are senior to miller.empno=B. emp B where A.empno=B. emp B where A.*. OR select * from emp where deptno= 10 and sal > (select sal from emp where ename='ALLEN') . loc from emp.* from emp A.empno) . salgrade Where grade > (select grade from emp.empno) order by A.deptno = dept. SQL> 226.deptno and sal between losal and hisal List the emps whose grade are > the grade of miller. loc.deptno = 10 and A.empno) . List the emps who belongs to dept 10 and sal > allen’s sal Select A. ename.sal > (select sal from emp where B.loc of all the emps belong to king’s dept Select empno. sal. Select A. List the emps whose job is same as either allen or sal > allen Select * from emp where ename <> 'ALLEN' AND (job = (select job from emp where ename = 'ALLEN') or sal > (select sal from emp where ename = 'ALLEN')) . dname. grade from emp. ename.hiredate . emp B where A. dname. SQL> 222.ename = 'BLAKE' and emp.mgr = B.

List the details of most recently hired emp of dept 30.deptno = dept. salgrade Where loc in ('DALLAS'. c) The total remuneration (Sal+comm.dept where dname='SALES' and emp2.0) from emp2. SQL> 229.hiredate)/12 > (select months_between(sysdate.deptno and sal between losal and hisal .'SMITH') and emp.deptno=dept.0) from emp2.’BLAKE’)) .) of all sales person of sales dept belongs to emp2 table.hiredate)/12 from emp where ename = 'SMITH')) and ename not in ('ADAMS'. Select * from emp where sal in (select sal from emp where ename = 'FORD') UNION (select sal from emp where ename = 'BLAKE') .null.deptno=dept. of result columns. 230.deptno) or sal in (select sal from emp4. SQL> List the emps who are belongs to dallas or Chicago with the grade same as adams or exp more than smith.'CHICAGO') and (grade = (select grade from emp. SQL> 231.deptno) union (select sal from emp4. dept.salgrade where grade=4) or sal in (select sal from emp5) . Select * from emp where sal in (select sal from emp where ename in(‘FORD’.dept where dname='SALES' and emp2. SQL> . SQL> List the emps whose sal is same as any one of the following: a) Sal of any clerk of emp1 table.227. of result columns. GIVING ERROR : ‘Query block has incorrect no. d) Any grade 4 emps sal of emp4 table e) Any emp sal of emp5 table Select * from emp Where sal 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(comm.salgrade where ename='ADAMS' and sal between losal and hisal) or months_between(sysdate.null. GIVING ERROR : ‘Query block has incorrect no. Select * from emp Where sal in (select sal from emp1 where job = 'CLERK') union (select sal from emp2 where hiredate > '01-JAN-83' ) union (select sal+decode(comm. Select * from emp where hiredate = (select max(hiredate) from emp where deptno = 30) and deptno = 30. Select * from emp.‘ List the highest paid emp Select * from emp where sal = (select max(sal) from emp) .‘ 228. b) Any emp of emp2 joined before 83.salgrade where grade=4) union (select sal from emp5) . List the emps whose sal is same as ford or blake.

*.deptno and sal between losal and hisal OR select emp.salgrade. SQL> List the highest paid emp of Chicago joined before the most recently hired emp of grade 2.deptno))) and loc = 'CHICAGO' and emp. Select * from emp where sal = (select max(sal) from emp where mgr=(select empno from emp where ename='KING')) . select emp. SQL> List the highest paid emp working under king.dept where loc = 'CHICAGO' and grade=2 and sal between losal and hisal and emp. select greatest(sysdate.dept where loc = 'CHICAGO' and grade=2 and sal between losal and hisal and emp. END OF BOOK QUERIES List the second highest paid emp Select * from emp where sal = (select max(sal) from emp where sal in (select sal from emp where sal < (select max(sal) from emp))) . SQL> 235. 234.232.loc from emp. Find the oldest date between current date and ‘01_JAN-83’.deptno = dept.deptno))) and loc = 'CHICAGO' and grade=2 and emp.salgrade.deptno = dept.salgrade where hiredate < (select max(hiredate) from emp where hiredate in (select hiredate from emp where hiredate < (select max(hiredate) from emp.loc from emp.'01-JAN-83') from dual .deptno SPENT 40 MINUTES ON THE ABOVE QUERY 233.deptno = dept.dept where hiredate < (select max(hiredate) from emp where hiredate in (select hiredate from emp where hiredate < (select max(hiredate) from emp.deptno = dept. SQL> .dept.*.

Sign up to vote on this title
UsefulNot useful