SQL QUERIES

1) Display the details of all employees
Desc emp;
2) Display the depart information from department table
Desc dept
3) Display the name and job for all the employees
Select ename, job from emp;
4) Display the name and salary for all the employees
Select ename, sal from emp;
5) Display the employee no and totalsalary for all the employees
Select empno, sal+nvl(comm,0) totalsalary from emp;
6) Display the employee name and annual salary for all employees.
Select ename, 1!(sal+"vl(comm,0)) from emp;
7) Display the names of all the employees #ho are #or$in% in depart number
10.
Select * from emp where deptno=10
) Display the names of all the employees #ho are #or$in% as cler$s and
dra#in% a salary more than &000.
!) Display the employee number and name #ho are earnin% comm.

10) Display the employee number and name #ho do not earn any comm.
11) Display the names of employees #ho are #or$in% as cler$s,salesman or
analyst and dra#in% a salary more than &000.
12) Display the names of the employees #ho are #or$in% in the company for
the past ' years;
13) Display the list of employees #ho have joined the company before
14) Display current Date.
15) Display the list of all users in your database(use catalo% table).
16) Display the names of all tables from current user;
17) Display the name of the current user.
1) Display the names of employees #or$in% in depart number 10 or 0 or (0
or employees #or$in% as
)*+,-S,S.*+S/." or .".*0S1.
1!) Display the names of employees #hose name starts #ith alaphabet S.
20) Display the +mployee names for employees #hose name ends #ith alaphabet
S.
21) Display the names of employees #hose names have second alphabet . in
their names.
22) select the names of the employee #hose names is e2actly five characters
in len%th.
23) Display the names of the employee #ho are not #or$in% as /.".3+,S.
24) Display the names of the employee #ho are not #or$in% as S.*+S/." 4,
)*+,- 4, .".*0S1.
in(5S.*+S/."5,5)*+,-5,5.".*0S15);
25) Display all ro#s from emp table.1he system should #ait after every
screen full of informaction.
26) Display the total number of employee #or$in% in the company.
27) Display the total salary bei%in% paid to all employees.
2) Display the ma2imum salary from emp table.
2!) Display the minimum salary from emp table.
30) Display the avera%e salary from emp table.
31) Display the ma2imum salary bein% paid to )*+,-.
32) Display the ma2imum salary bein% paid to depart number 0.
33) Display the minimum salary bein% paid to any S.*+S/.".
34) Display the avera%e salary dra#n by /.".3+,S.
35) Display the total salary dra#n by .".*0S1 #or$in% in depart number (0.
deptno6(0;
36) "#$pla% the name$ of the emplo%ee #n order of $alar% #&e the
name of
the emplo%ee earn#n' lowe$t $alar% should salary appear first.
37) Display the names of the employee in descendin% order of salary.
3) Display the names of the employee in order of employee name.
3!) "#$pla% empno,ename,deptno,$al $ort the o(tp(t f#r$t ba$e on
name and
w#th#n name b% deptno and w#th #n deptno by sal.
40) Display the name of the employee alon% #ith their annual
salary(sal!1).1he name of the employee earnin% hi%hest annual salary should
apper first.
41) "#$pla% name,$alar%,hra,pf,da,total $alar% for each emplo%ee&
)he
o(tp(t $ho(ld be #n the order of total salary,hra 1'7 of salary,da 107 of
salary,pf '7
salary,total salary #ill be(salary+hra+da)8pf.
42) Display depart numbers and total number of employees #or$in% in each
department.
43) Display the various jobs and total number of employees #ithin each job
%roup.
44) Display the depart numbers and total salary for each department.
45) Display the depart numbers and ma2 salary for each department.
46) Display the various jobs and total salary for each job
47) Display the various jobs and total salary for each job
4) Display the depart numbers #ith more than three employees in each dept.
4!) Display the various jobs alon% #ith total salary for each of the jobs
#here total salary is %reater than (0000.
50) Display the various jobs alon% #ith total number of employees in each
job.1he output should contain only those jobs #ith more than three employees.
51) Display the name of the empployee #ho earns hi%hest salary.
52) Display the employee number and name for employee #or$in% as cler$ and
earnin% hi%hest salary amon% cler$s.
53) Display the names of salesman #ho earns a salary more than the hi%hest
salary of any cler$.
54) "#$pla% the name$ of cler*$ who earn a $alar% more than the
lowe$t
$alar% of an% $ale$man&
"#$pla% the name$ of emplo%ee$ who earn a $alar% more than
that of
+one$ or that of $alar% 'rether than that of scott.
55) Display the names of the employees #ho earn hi%hest salary in their
respective departments.
56) Display the names of the employees #ho earn hi%hest salaries in their
respective job %roups.
57) Display the employee names #ho are #or$in% in accountin% department.
5) Display the employee names #ho are #or$in% in )hica%o.
5!) Display the 9ob %roups havin% total salary %reater than the ma2imum
salary for mana%ers.
60) Display the names of employees from department number 10 #ith salary
%rether than that of any employee #or$in% in other department.
61) Display the names of the employees from department number 10 #ith
salary %reater than that of all employee #or$in% in other departments.
62) Display the names of the employees in :ppercase.
63) Display the names of the employees in *o#ecase.
64) Display the names of the employees in ;ropercase.
65) Display the len%th of 0our name usin% appropriate function.
66) Display the len%th of all the employee names.
67) select name of the employee concatenate #ith employee number.
6) :ser appropriate function and e2tract & characters startin% from
characters from the follo#in% strin% 54racle5. i.e the out put should be
5ac5.
6!) <ind the <irst occurance of character 5a5 from the follo#in% strin% i.e
5)omputer /aintenance )orporation5.
70) ,eplace every occurance of alphabhet . #ith = in the strin% .llens(use
translate function)
71) Display the informaction from emp table.>here job mana%er is found it
should be displayed as boos(:se replace function).
72) Display empno,ename,deptno from emp table.?nstead of display department
numbers display the related department name(:se decode function).
73) Display your a%e in days.
74) Display your a%e in months.
75) Display the current date as 1'th .u%est <riday "ineteen "inety Saven.
76) Display the follo#in% output for each ro# from emp table.
scott has joined the company on #ednesday 1&th .u%ust ninten nintey.
77) <ind the date for nearest saturday after current date.
7) Display current time.
7!) Display the date three months =efore the current date.
0) Display the common jobs from department number 10 and 0.
1) Display the jobs found in department 10 and 0 +liminate duplicate jobs.
2) Display the jobs #hich are uni@ue to department 10.
3) Display the details of those #ho do not have any person #or$in% under
them.
4) Display the details of those employees #ho are in sales department and
%rade is &.
5) Display those #ho are not mana%ers and #ho are mana%ers any one.
i)display the mana%ers names
ii)display the #ho are not mana%ers
6) Display those employee #hose name contains not less than ( characters.
7) Display those department #hose name start #ith ASA #hile the location
name ends #ith A-A.
) Display those employees #hose mana%er name is 94"+S.
!) Display those employees #hose salary is more than &000 after %ivin% 07
increment.
!0) Display all employees #hile their dept names;
!1) Display ename #ho are #or$in% in sales dept.
!2) Display employee name,deptname,salary and comm for those sal in bet#een
000 to '000 #hile location is chica%o.
!3)Display those employees #hose salary %reter than his mana%er salary.
!4) Display those employees #ho are #or$in% in the same dept #here his
mana%er is #or$.
!5) Display those employees #ho are not #or$in% under any mana%er.
!6) Display %rade and employees name for the dept no 10 or &0 but %rade is
not ( #hile joined the company before &18dec8B.
!7) :pdate the salary of each employee by 107 increment #ho are not
eli%ibl# for commission.
!) S,-,.) tho$e emplo%ee who jo#ned the compan% before 31/
dec/2 wh#le
the#r dept locat#on #$ new%or* or )hica%o.
!!) D?S;*.0 +/;*40++ "./+,94=,D+;.,1/+"1,*4).1?4" <4, .** >C4 .,+ >4,-?"3
.S /.".3+,D
100) D?S;*.0 1C4S+ +/;*40++S >C4S+ /.".3+, "./+ ?S 94"+SD 88
E."D .*S4 D?S;*.0 1C+?, /.".3+, "./+FD
101) Display name and salary of ford if his salary is e@ual to hisal of his
%rade
a)select ename,sal,%rade from emp,sal%rade #here sal bet#een losal and
hisal
and ename 65<4,D5 ."D C?S.*6S.*;
102) Display employee name,job,depart name ,mana%er name,his %rade and ma$e
out an under department #iseD
103) -#$t o(t all emplo%ee$ name,job,$alar%,'rade and depart
name for e0er%
one #n the compan% e2cept 5)*+,-5.Sort on salary display the hi%hest
salaryD
104) Display the employee name,job and his mana%er.Display also employee #ho
are #ithout mana%erD
105) <ind out the top ' earners of companyD
106) Display name of those employee #ho are %ettin% the hi%hest salaryD
107) Display those employee #hose salary is e@ual to avera%e of ma2imum and
minimumD
10) Select count of employee in each department #here count %reater than
&D
10!) Display dname #here at least & are #or$in% and display only department
nameD
110) Display name of those mana%ers name #hose salary is more than avera%e
salary of his companyD
111)Display those mana%ers name #hose salary is more than avera%e salary of
his employeeD
112) Display employee name,sal,comm and net pay for those employee
#hose net pay is %reter than or e@ual to any other employee salary of
the companyD
113) Display all employees names #ith total sal of company #ith each
employee nameD
114) <ind out last '(least)earners of the company.D
115) <ind out the number of employees #hose salary is %reater than their
mana%er salaryD
116) Display those department #here no employee #or$in%D
SG*Hselect dname from emp,dept #here emp.deptno not in(emp.deptno)
117) Display those employee #hose salary is 4DD valueD
11) Display those employee #hose salary contains alleast & di%itsD
11!) Display those employee #ho joined in the company in the month of DecD
120) Display those employees #hose name contains A.AD
or
121) Display those employee #hose deptno is available in salaryD
122) Display those employee #hose first characters from hiredate 8last
characters of salaryD
123) Display those employee #hose 107 of salary is e@ual to the year of
joinin%D
124) Display those employee #ho are #or$in% in sales or researchD
125) Display the %rade of jonesD
126) Display those employees #ho joined the company before 1' of the monthD
127) Display those employee #ho has joined before 1'th of the month.
12) Delete those records #here no of employees in a particular department
is less than &.
12!) Display the name of the department #here no employee #or$in%.
130) Display those employees #ho are #or$in% as mana%er.
131) Display those employees #hose %rade is e@ual to any number of sal but
not e@ual to first number of salD
132) ;rint the details of all the employees #ho are Sub8ordinate to =*.-+D
133) Display employee name and his salary #hose salary is %reater than
hi%hest avera%e of department numberD
134) Display the 10th record of emp table(#ithout usin% ro#id)
135) Display the half of the ename5s in upper case and remainin% lo#ercaseD
136) Display the 10th record of emp table #ithout usin% %roup by and ro#idD
Delete the 10th record of emp table.
137) )reate a copy of emp table;

13) Select ename if ename e2ists more than once.
13!) Display all enames in reverse orderD(S/?1CIC1?/S).
140) Display those employee #hose joinin% of month and %rade is e@ual.
141) Display those employee #hose joinin% D.1+ is available in deptno.
142) Display those employees name as follo#s
. .**+"
= =*.-+
143) *ist out the employees ename,sal,;<(07 4< S.*) from emp;
144) )reate table emp #ith only one column empno;
145) .dd this column to emp table ename vrachar(0).
146) 4ops ? for%ot %ive the primary $ey constraint. .dd in no#.
147) "o# increase the len%th of ename column to &0 characters.
14) .dd salary column to emp table.
14!) ? #ant to %ive a validation sayin% that salary cannot be %reater 10,000
(note %ive a name to this constraint)
150) <or the time bein% ? have decided that ? #ill not impose this
validation./y boss has a%reed to pay more than 10,000.
drop constraint ch$J001 (or)Disable the constraint by usin% alter table emp
modify constraint ch$J001 disable;
151) /y boss has chan%ed his mind. "o# he doesn5t #ant to pay more than
10,000.so revo$e that salary constraint.
152) .dd column called as m%r to your emp table;
153) 4hK 1his column should be related to empno. 3ive a command to add this
constraint.

154) .dd deptno column to your emp table;
155) 1his deptno column should be related to deptno column of dept table;
156) 3ive the command to add the constraint.
157) )reate table called as ne#emp. :sin% sin%le command create this table
as #ell as %et data into this table(use create table as);
15) Delete the ro#s of employees #ho are #or$in% in the company for more
than years.
15!) ;rovide a commission(107 )omm 4f Sal) to employees #ho are not earnin%
any commission.
160) ?f any employee has commission his commission should be incremented by
107 of his salary.
161) Display employee name and department name for each employee.
162)Display employee number,name and location of the department in #hich he
is #or$in%.
163) Display ename,dname even if there are no employees #or$in% in a
particular department(use outer join).
164) Display employee name and his mana%er name.
165) Display the department name and total number of employees in each
department.
166)Display the department name alon% #ith total salary in each department.
167) Display itemname and total sales amount for each item.
16) >rite a Guery 1o Delete 1he ,epeted ,o#s from emp table;
16!) 14 D?S;*.0 ' 14 L ,4>S <,4/ . 1.=*+
170) D?S;*.0 14; " ,4>S <,4/ 1.=*+D
171) D?S;*.0 14; & S.*.,?+S <,4/ +/;;
172) D?S;*.0 Mth <,4/ 1C+ +/; 1.=*+D