Oracle Queries

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 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 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-81'; List the Empno, Ename, Sal, Daily Sal of all Employees in the ASC order of AnnSal. select SAL,(SAL + nvl(comm,0)) from emp order by (SAL + nvl(comm,0)) ASC Display the empno , ename, job, hiredate, exp of all Mgrs select empno, ename, job, hiredate, months_between(sysdate,hiredate)/12 as "Experience in years" 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 as "Exepereince in years" from emp where MGR = 7839 Display the details of the emps whose Comm. Is more than their sal. select * from emp where nvl(comm,0) > sal List the emps in the asc order of Designations select * from emp order by job ASC List the emps along with their exp and daily sal is more than Rs.100 select * 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')

010. SQL> 011. SQL> 012. SQL> 013. SQL> 014. SQL>

19Jan80 in asc order of seniority.31Dec81. SQL> 028. SQL> 026.'19-JAN-80') order by hiredate ASC List the emps who are working for the deptno 10 or 20 select * from emp where deptno in ('10'. select ename from emp where hiredate in ('1-MAY-81'. 'YY') like '80' List the emps who does not belong to deptno 20 select * from emp where deptno not like '20' 016. SQL> 029. SQL> 021. 17Dec81.'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. SQL> 023. SQL> 027. SQL> 017. SQL> 024.'17-DEC-81'. 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 to_char(hiredate. SQL> 020. SQL> 022. SQL> . SQL> 019.order by job DESC 015.'MON') 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%' List the emps those who joined in 80’s select * from emp where to_char(hiredate. SQL> 018. SQL> List the emps who joined on 1May81. SQL> 025.'31-DEC81'.

SQL> 036. loc. dname of all the ‘Mgrs’ and ‘Analyst’ working in NEWYORK. select * from emp where job = 'CLERK' and deptno = '20' List the emps of deptno 30 or10 joined in the year 1981 select * from emp where deptno in ('30'.'ANALYST') and months_between(sysdate. deptno. DALLAS with an exp more than 7 years without receiving the Comma Asc order of Loc. SQL> 038. salgrade where sal between losal and hisal order by SQL> 042.hiredate)/12 > 7 order by job ASC List the empno. List the emps who joined in before or after 1981 select * from emp where to_char(hiredate. ename. select * from emp where job in('MANAGER'. job of all emps working at CHICAGO or working for ACCOUNTING dept wit ann sal > 28000. SQL> 033. sal. 'RESEARCH') order by job ASC List the empno. SQL> 039. dname. SQL> 034. SQL> 041. List all the emps except ‘president’ & ‘Mgr’ in asc order of salaries select * from emp where job!=ALL('PRESIDENT'.'10') and to_char(hiredate. SQL> 040. SQL> 035. sal. SQL> 037. SQL> 031. SQL> 032.030. 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. SQL> . 'MON') not like 'MAR' List all the clerks of deptno 20. 'YY') like '81' Display the details of ‘Smith’ select * from emp where ename = 'SMITH' Display the location of ‘Smith’ select loc from emp where ename = 'SMITH' 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 * from emp where job in ('ACCOUNTING'.'MANAGER') order by job ASC. Display the total information of the emps along with grades in the asc order select * from emp. ename. 'YY') != 80 List the emps whose empno not starting with digit 78 select * from emp where empno not like '78__' List the emps who are working under ‘Mgr’ List the emps who joined in any year but not belongs to the month of March select * from emp where to_char(hiredate.

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.hiredate < (select hiredate from emp B where B. SQL> 049.'ANALYST') List the empno. SQL> 048. SQL> 046.'salgrage' ASC 043. sal. 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 A. ename.3) and sal between losal and hisal Display all grade 4. dept. exp. SQL> 052. dept. ename or without the emps Select empno. SQL> . SQL> 051. SQL> 044. SQL> 053.5 Analyst and Mgr select * from emp. select * from emp where sal in (select sal from emp where ename in SQL> 047.deptno=dept.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') List the emps whose Sal is same as FORD or SMITH in desc order of Sal. List the details of the emps whose salaries more than the employee BLAKE select * from emp where SAL > (select sal from emp where ename = 'BLAKE') List the details of the emps whose job is same as ALLEN.5) and sal between losal and hisal and job in ('MANAGER'.dept where emp. SQL> 050.deptno in (10.20) and emp.empno = A. salgrade where grade in(4. List the details of the depts along with empno. List all the grade2 and grade 3 emps select * from emp. grade. ann sal of emps working for dept 20 or 10. SQL> 045.deptno=dept.* from emp. ename. dname. select * from emp.deptno . salgrade where emp. salgrade where grade in (2.

b) ¾ Sal of any Mgr of Emp2 table.'BOSTON') and emp. select MAX(sal) from emp 057.salgrade.deptno List the emps of Grade 3. SQL> 058. SQL> List the emps who’s Jobs are same as MILLER or Sal is more than ALLEN.('FORD'.'SMITH') Write a Query to display the details of emps whose Sal is same as of a) Employee Sal of Emp1 table. . c) The Sal of any sales person with exp of 5 yrs belongs to the sales dept of emp3 table.'SMITH')) and ename not in ('FORD'. select * from emp where sal >(select SUM(sal) from emp where job = 'SALESMAN') List the emps who are Senior to ‘BLAKE’ working at CHICAGO & BOSTON.deptno = dept.deptno = dept. SQL> 059. select * from emp. SQL> . select * from emp where job = (select job from emp where ename = 'MILLER') or sal > (select sal from emp where ename = 'ALLEN') List the emps whose Sal is > the total remuneration of the SALESMAN.'SMITH') order by sal DESC 054. select * from emp. List the jobs of Deptno 10 those are not found in dept 20. SQL> 056.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> 061. e) Any Grade 2&3 employee working for SALES dept or OPERATIONS dept joined in 89. select * from emp where job in (select job from emp where ename in ('ALLEN'.'SMITH')) and ename not in ('ALLEN'. SQL> 060.dept where grade in ('3'.'4') and dname in ('ACCOUNTING'.dept where hiredate < (select hiredate from emp where ename = 'BLAKE') and loc in ('CHICAGO'.'RESEARCH') and sal > (select sal from emp where ename = 'ALLEN') and hiredate < (select hiredate from emp where ename = 'SMITH') and emp. 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> 062.deptno and sal between losal and hisal order by hiredate ASC List the emps whose jobs same as ALLEN Or SMITH. SQL> 055. d) Any Grade 2 employees of Emp4 table.

SQL> 065. List the emps who joined in 81 with job same as the most senior person of year 81. SQL> 067. SQL> 068. SQL> 075. select * from emp where sal = (select MAX(sal) from emp) Find the highest paid employee of sales dept. SQL> 070. SQL> 072. SQL> 066. SQL> 076. Display the number of emps for each job group deptno wise . Find the details of highest paid employee.063. SQL> 071. SQL> Find the total sal given to the ‘MGR’ Find the total annual sal to distribute job wise in the year 81 Display the total sal of emps belong to Grade 3. SQL> 069. List the most senior emp working under KING and Grade is more than 3. SQL> 074. SQL> 064. List the most recently hired emp of grade 3 belongs to the Loc CHICAGO List the emps who are senior to most recently hired emp who is working under Mgr KING 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 Display the details of most senior employee belongs to 1981. SQL> 073. Display the avg salaries of all CLERKS List the emps in dept 20 whose sal is > the avg sal of deptno 10 emps.

no of emps where atleast two emps are ‘CLERKS’ List the details of the dept where the max no of emps are working Display the emps whose Mgr name is Jones List the emps whose salary is more than 3000 after giving 20% increment List the emps with their dept names. SQL> 085. SQL> List the Mgr no & no. loc for those who are working as a ‘MGRs’ List the emps whose mgr name is ‘JONES’ and also list their manager name List the name and salary of FORD if his salary is equal to hisal of his Grade . SQL> 080.077. SQL> 089. SQL> 083. Display dname. employee name for the deptno 10 or deptno 30 but salgrade is not 4 while they joined the company before ’31-DEC-82’ List the name. SQL> 078. List the emps who are not working in sales dept List the emps name. dept. SQL> 081. SQL> 079. For those whose salary is between 2000 and 5000 while loc is CHICAGO List the emps whose salary is > his Manager’s salary. SQL> 091. SQL> 090. SQL> 086. SQL> 087. grade. of emps working for those Mgrs in the asc Mgrno. dname. sal & comm. SQL> 084. number of emps. Display the grade. SQL> 082. SQL> 088. List the dept details where at least two emps are working. List the grade. job. max sal of each grade.

SQL> 097. List the names of depts. SQL> 094. List the no of emps in each dept where the number is more than 3. For those emps whose net pay is > or = any other employee salary of the company. job and Manager who are without Manager. grade and dname except ‘CLERK’s and sort on the basis of highest salary. job. SQL> 093. List the Mgrs who are not working under ‘PRESIDENT’ but are working under other Manager. sal. List the names of emps who are getting the highest salary dept wise. SQL> 095. SQL> 101. SQL> 106. SQL> 104. job. Manager. And net pay is more than any other . SQL> 105. List the emps name. SQL> 098. SQL> 107. Find out least 5 earners of the company. salary. dname. SQL> 096. List the records from emp whose deptno is not in dept List the name. List the emps name. Grade dept wise. salary. SQL> 100. comm. sal. List the emps whose salary is equal to average of maximum and minimum. Where at least 3 emps are working in each dept. List the name. comm. SQL> 099. SQL> 102. SQL> 103.092. List the managers whose salary is more than his emps avg sal. List the emps whose sal < his Manager but more than other Manager List the employee names and his annual salary dept wise. Find out the no of emps whose salary is > their Manager salary. List the name.

[AT PRESENT THERE ARE 6 EMPS] IF U DON’T CHANGE THE ABOVE. 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. List the emps whose first 2 chars from hiredate = last 2 chars of salary. SQL> 108. OF EMPS = NO OF CHARS IN THE DNAME. 118. SQL> 116. SQL> 112. SQL> 115. SQL> 117. List the emps whose 10% of sal is equal to year of Joining List first 50% of chars of ename in lower case and remaining are upper case. List the emps whose sal contain 3 digits List the emps who joined in the month of ‘DEC’ List the emps whose names contains ‘A’ List the emps whose deptno is available in his salary. List the enames who are retiring after ’31-DEC-89’ the max job period is 20Y. List the dname whose no of emps is = to no of chars in the dname. SQL> 109. U GET THE WRONG O/P FOR THE SAME. SQL> 114. SQL> 111.employee. . SQL> 113. SQL> 110. TO GET THE OUTPUT. AT PRESET THERE ARE NO SUCH DNAME WHERE NO. SQL> THIS QUERY WILL WORK AFTER MODIFING EMP TABLE. List those emps whose sal is odd value. SQL> List the emps those who joined in company before 15th of the month.

no of emps are working List the managers name who is having max no of emps working under him List the ename and sal is increased by 15% and expressed as no of dollars.119. no of chars of which is no of emp’s in any other dept 120. . SQL> 129. SQL> 122. SQL> List the dname. List the emps who are working as managers List the name of dept where highest no of emps are working Count the no of emps who are working as ‘Managers’ (using set option) List the emps who joined in the company on the same date List the details of the emps whose grade is equal to one tenth of sales dept. SQL> 126. SQL> 121. SQL> 127. SQL> List the emps with hiredate in format June 4. SQL> 124. Produce the output of EMP table ‘EMP_AND_JOB’ for ename and job Produce the following output from EMP EMPLOYEE ---------------SMITH(clerk) ALLEN(salesman) SQL> 130.1988. SQL> 123. List the name of the dept where more than avg. SQL> 125. SQL> 128.

SQL> 134. ‘99/98’ Emps hired on or before 15th of any month are paid on the last Friday of that month. Those hired after 15th are paid on the first Friday of the following month. List the emps who are working as managers using co-related subquery . SQL> 138. ‘NO’ if not valid. Write a query to return the day of the week for any date entered in format ‘DD-MM-YY’ Wrote a query to calculate the length of service of any employee with the company. SQL> 141. Print a list of emps. ‘12/34’. SQL> 133. ‘01/la’. Print the expression ‘YES’ if valid.131. their hiredate and the first pay date. SQL> 136. Print the details of all the emps who are sub-ordinates to BLAKE. ??? List those managers who are getting less than his emps salary. SQL> 137. SQL> List those emps whose salary contains first two digit of their deptno. SQL> 140. Find out the emps who are getting decimal value in their sal without using like operator. SQL> Print a list of emp’s listing ‘just salary’ if salary is more than 1500. 132. Use the following values to test your solution. ‘On target’ if salary is 1500 and ‘Below 1500’ if salary is less than 1500. SQL> 139. use DEFINE to avoid repetitive typing of functions Give a string of format ‘NN/NN’. Count the no of characters without considering spaces for each name. SQL> 135. Sort on hiredate. verify that the first and last two characters are numbers and that the middle character is ‘/’.

SQL> 153. SQL> 143. and grade who earn 36000 a year or who are not CLERKS. Use the variable in a statement which finds all emps who can earn 30000 a year or more. Find avg sal and avg total remuneration for each job type. List the emps who are drawing less than 1000. SQL> 151. deptno. Check whether all the emps numbers are indeed unique. 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. annual sal. SQL> List the emps whose Mgr name is ‘JONES’ and also with his Manager Name. Find out how many managers are there in the company. Remember salesman earn commission. job. List all the emps by name and number along with their manager’s name and number also list KING who has no ‘Manager’ 152. SQL> 146. Sort in des order of sal . sort the output by salary. 150. SQL> 149. SQL> 147. SQL> Find all the emps who earn minimum sal for each job wise in asc order of sal Find out all the emps who earn highest sal in each job type.142. SQL> 144. Define a variable representing the expression used to calculate on emps total annual remuneration. dept name. SQL> Find out the emps who joined in the company before their managers. List the employee name. SQL> 145. SQL> 148.

SQL> 158 SQL> 159. List out the name. job. SQL> List the deptno. SQL> 157.154. List the empno. SQL> Find out the most recently hired emps in each dept order by hiredate List the emp name. Of the salesman List the deptno and their avg salaries for dept with the avg salary less than the avg for all departments. SQL> 160. SQL> 165. SQL> 161. List the deptno. SQL> 155. sal of the emps in the department with the highest avg sal. job. sal and deptno for each emp who earns a sal greater than the avg for their dept order by deptno 156. List the name. name. name. Of the emps who earn the second highest earnings (sal+comm) 162. SQL> 164. SQL> 166. salary and sal+comm. Find the max avg salary drawn for each job except for ‘PRESIDENT’ Find the name and job of the emps who earn Max salary and Commission. sal and comm. SQL> 163. job. 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. 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. of emps . salary and sal+comm. SQL> List the deptno where there are no emps List the no of emps and avg salary within each dept for each job.

SQL> 172. daily sal of all salesman in the asc ann sal. SQL> 173. SQL> 168. List the emps whose exp is more than 10 years. ename. ename. SQL> List the emps whose ann sal is < 25000 in the asc order of salaries List the empno. List the empno. gross.sal TA 30%. ann sal. SQL> List the details of the emps in the asc order of salary. Display the unique dept with jobs. deptno of dept 10 emps in the asc order of sal. List empno. HRA 50%. ename. LIC.sal. SQL> 179. SQL> 178. SQL> 169. SQL> 170. SQL> 176. SQL> 171. Display the details of BLAKE. SQL> 181. ename Display the unique dept of emps. SQL> 180. hiredate. . net allowances and net sal in the asc order of net sal.167. Ename. SQL> 174. List all CLERKs List all emps joined on 1 May 81. net deductions. SQL> 175.sal for all emp joined before 1 apr 81 177. current date & exp in the asc order of exp. List the emps whose salaries are less than 3500. List the emps Empno. PF. List the dept in asc order of job and the desc order of emps print empno. List the empno. DA 40%. ename.

List the emps who joined in year 81. List the emps who are either CLERKs or MANAGERs. SQL> 184. SQL> List the emps who are working as Mgrs. 189. SQL> 188. List the emps who joined in the second half of 82. 7900. SQL> 197. SQL> 185. List the emps who joined in the following dates : 1 may 81. SQL> 186. SQL> 195. 30 dec 81. SQL> 193. List the emps names starting with ‘M’ with 5 chars List the emps names end with ‘H’ all together 5 chars. 7890. SQL> 196. SQL> 192. List the emps who joined in the month of jan List the emps who joined in the month having a char ‘a’ List the emps who joined in the month having a second char is ‘A’ . List the emps working under the Mgrs 7369. SQL> 191. SQL> List all the 4 chars emps. SQL> 190. 17 nov 81. List the names start with ‘M’ List the emps who joined in the year 81 List the emps whose sal is ending with 00. SQL> 194. 7654. SQL> 187.182. List the emps whose ann sal ranging from 23000 to 40000. SQL> 183.

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. SQL> 209. ename. 20 or 30 in des order 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 empno.. job of emps with the ann sal < 34000 but receiving some comm. List the emps whose salary is 4 digit no. > 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.. SQL> 207. SQL> 205. sal. SQL> 202. SQL> 203. List the unique jobs of depts. List the emps joined in Jan with salary ranging from 1500 to 4000. SQL> . [???] List the details of emps working at CHICAGO. ename. SQL> 206. SQL> 201.198. SQL> 199. SQL> 204. job. List the emps who are either clerks with an exp more than 8y List the Mgrs of dept 10 or 20. Which should not be > sal and designation should be salesman working for dept 30.. SQL> 208. deptno & exp of all emps belongs to dept 10 or 20 with an exp 6 to 10 yrs working under some mgr without comm. SQL> 200. 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. List the empno. List the emps who are working as either mgr or analyst with sal ranging from 2000 and 5000 and without comm. but not belongs to months of MAR. sal. APR & SEP and working for mgrs & no is not ending with 88 or 56. List the emps who joined in 80’s.

new york with sal ranging from 2000 to 5000 joined in 81. SQL> 224.deptno. List the emps along with loc of those who belongs to Dallas. ename. List the emps who are senior to miller. SQL> 223. loc of all emps working at CHICAGO. SQL> 214. SQL> 221. SQL> 220. 10 or 20. SQL> 213. sal. List the empno. SQL> 222. ename. List the emps whose job is same as either allen or sal > allen List the emps who are senior to their own mgr. . SQL> 211.210. SQL> 219. grade of all emps. loc. dname of all depts. SQL> 216. List the emps whose job is same as smith. List the emps whose sal > blake’s List the emps who belongs to dept 10 and sal > allen’s sal List the Mgrs who are senior to king & who are junior to smith. loc of all emps List the empno. List the empno. SQL> 212. SQL> 218. List the grade 2&3 emp of Chicago List the emps with loc & grade of accounting dept or the locs Dallas or Chicago with the grades 3 to 5 & exp > 6y. ename. SQL> 215. sal. List the grade 3 emps of research & operations depts. SQL> List the empno. SQL> 217. DALLAS with an exp> 6yrs. Joined after 1987 and whose names should not be either miller or allen.

loc of all the emps belong to king’s dept List the emps whose grade are > the grade of miller. List the empno. SQL> 232. SQL> 231. c) The total remuneration (Sal+comm. END OF BOOK QUERIES List the second highest paid emp Find the oldest date between current date and ‘01_JAN-83’. dname. SQL> 229. List the emps whose sal is same as ford or blake. List the highest paid emp of Chicago joined before the most recently hired emp of grade 2. SQL> 226. List the emps whose sal is same as any one of the following: a) Sal of any clerk of emp1 table. loc. SQL> 234. d) Any grade 4 emps sal of emp4 table e) Any emp sal of emp5 table List the highest paid emp List the details of most recently hired emp of dept 30. SQL> 230. sal. SQL> 233. SQL> 227. b) Any emp of emp2 joined before 83.) of all sales person of sales dept belongs to emp2 table. SQL> 228. SQL> List the highest paid emp working under king. SQL> 235. ename. List the emps who are belongs to dallas or Chicago with the grade same as adams or exp more than smith.225. .

Sign up to vote on this title
UsefulNot useful