SlideShare a Scribd company logo
1 of 22
1.)waqtfo all the list of tables ?
SQL> select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
2.)waqtfo all the dept details ?
SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
3.)waqtfo the deptno from dept table ?
SQL> select deptno from dept;
DEPTNO
----------
10
20
30
40
4.)waqtfo location and deptno from dept ?
SQL> select deptno, loc from dept;
DEPTNO LOC
---------- -------------
10 NEW YORK
20 DALLAS
30 CHICAGO
40 BOSTON
5.)waqtfo all the dept details ?
SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
6.)waqtfo all the dept name and deptno from the dept table ?
SQL> select dname, deptno from dept;
DNAME DEPTNO
-------------- ----------
ACCOUNTING 10
RESEARCH 20
SALES 30
OPERATIONS 40
7.)waqtfo all the employee names and their corresponding salary ?
SQL> select ename, sal from emp;
ENAME SAL
---------- ----------
KING 5000
BLAKE 2850
CLARK 2450
JONES 2975
SCOTT 3000
FORD 3000
SMITH 800
ALLEN 1600
WARD 1250
MARTIN 1250
TURNER 1500
ADAMS 1100
JAMES 950
MILLER 1300
14 rows selected.
8.)waqtfo all the employee names and their job and salary ?
SQL> select ename, sal, job from emp;
ENAME SAL JOB
---------- ---------- ---------
KING 5000 PRESIDENT
BLAKE 2850 MANAGER
CLARK 2450 MANAGER
JONES 2975 MANAGER
SCOTT 3000 ANALYST
FORD 3000 ANALYST
SMITH 800 CLERK
ALLEN 1600 SALESMAN
WARD 1250 SALESMAN
MARTIN 1250 SALESMAN
TURNER 1500 SALESMAN
ADAMS 1100 CLERK
JAMES 950 CLERK
MILLER 1300 CLERK
14 rows selected.
9.)waqtfo all the employee names, salary and annual salary ?
SQL> select ename, sal, sal*12 from emp;
ENAME SAL SAL*12
---------- ---------- ----------
KING 5000 60000
BLAKE 2850 34200
CLARK 2450 29400
JONES 2975 35700
SCOTT 3000 36000
FORD 3000 36000
SMITH 800 9600
ALLEN 1600 19200
WARD 1250 15000
MARTIN 1250 15000
TURNER 1500 18000
ADAMS 1100 13200
JAMES 950 11400
MILLER 1300 15600
14 rows selected.
10.)waqtfo all the employee names, salary, annual salary and projected
annual salary, if it is increased by 11% ?
SQL> select ename, sal, sal*12, sal*12*1.11 from emp;
ENAME SAL SAL*12 SAL*12*1.11
---------- ---------- ---------- -----------
KING 5000 60000 66600
BLAKE 2850 34200 37962
CLARK 2450 29400 32634
JONES 2975 35700 39627
SCOTT 3000 36000 39960
FORD 3000 36000 39960
SMITH 800 9600 10656
ALLEN 1600 19200 21312
WARD 1250 15000 16650
MARTIN 1250 15000 16650
TURNER 1500 18000 19980
ADAMS 1100 13200 14652
JAMES 950 11400 12654
MILLER 1300 15600 17316
14 rows selected.
11.)waqtfo all the employee names, salary, annual salary and projected
annual salary, if it is increased by 11% using Alias keyword ?
SQL> select ename as emp_name, sal, sal*12, sal*12*1.11 as projected from
emp;
EMP_NAME SAL SAL*12 PROJECTED
---------- ---------- ---------- ----------
KING 5000 60000 66600
BLAKE 2850 34200 37962
CLARK 2450 29400 32634
JONES 2975 35700 39627
SCOTT 3000 36000 39960
FORD 3000 36000 39960
SMITH 800 9600 10656
ALLEN 1600 19200 21312
WARD 1250 15000 16650
MARTIN 1250 15000 16650
TURNER 1500 18000 19980
ADAMS 1100 13200 14652
JAMES 950 11400 12654
MILLER 1300 15600 17316
14 rows selected.
12.)waqtfo available deptno in emp table ?
SQL> select distinct deptno from emp;
DEPTNO
----------
30
20
10
13.)waqtfo all the employee names and employee no from emp using
concatenation alias keyword ?
SQL> select 'my name is .....'||ename||' '||empno as myname from emp;
MYNAME
-------------------------------------------------------------------
my name is .....KING 7839
my name is .....BLAKE 7698
my name is .....CLARK 7782
my name is .....JONES 7566
my name is .....SCOTT 7788
my name is .....FORD 7902
my name is .....SMITH 7369
my name is .....ALLEN 7499
my name is .....WARD 7521
my name is .....MARTIN 7654
my name is .....TURNER 7844
my name is .....ADAMS 7876
my name is .....JAMES 7900
my name is .....MILLER 7934
14 rows selected.
14.)waqtfo all the employee names who belong to deptno 10 ?
SQL> select ename from emp where deptno=10;
ENAME
----------
KING
CLARK
MILLER
15.)waqtfo all the employee names who is getting the salary greater than
1000 and lesser than 3000 ?
SQL> select ename from emp where sal>1000 and sal<3000;
ENAME
----------
BLAKE
CLARK
JONES
ALLEN
WARD
MARTIN
TURNER
ADAMS
MILLER
9 rows selected.
16.)waqtfo all the employee names who are working as CLERK ?
SQL> select ename from emp where job='CLERK';
ENAME
----------
SMITH
ADAMS
JAMES
MILLER
17.)waqtfo all the employee names have salary greater than 1000 lesser
than 3000 and working as either CLERK, SALESMAN or ANALYSIST and working
in a deptno 10,20 or 30 ?
SQL> select ename from emp where (sal>1000 and sal<3000) and (job='CLERK'
or job='SALESMAN' or job='ANALYST') and (deptno=10 or deptno=20 or
deptno=30);
ENAME
----------
ALLEN
WARD
MARTIN
TURNER
ADAMS
MILLER
6 rows selected.
18.)waqtfo all the employee names working in deptno 10 or 20 or 30 or 40 ?
SQL> select ename from emp where deptno in (10,20,30,40);
ENAME
----------
KING
BLAKE
CLARK
JONES
SCOTT
FORD
SMITH
ALLEN
WARD
MARTIN
TURNER
ADAMS
JAMES
MILLER
14 rows selected.
19.)waqtfo all the enames who are eligible for commision ?
SQL> select ename from emp where comm is not null;
ENAME
----------
ALLEN
WARD
MARTIN
TURNER
20.)waqtfo all the enames having managers ?
SQL> select ename from emp where MGR is not null;
ENAME
----------
BLAKE
CLARK
JONES
SCOTT
FORD
SMITH
ALLEN
WARD
MARTIN
TURNER
ADAMS
JAMES
MILLER
13 rows selected.
21.)waqtfo all the enames who are working in deptno 10 ?
SQL> select ename from emp where deptno=10;
ENAME
----------
KING
CLARK
MILLER
22.)waqtfo all the enames working in scott's dept ?
SQL> select ename from emp where deptno=(select deptno from emp where
ename='SCOTT');
ENAME
----------
JONES
SCOTT
FORD
SMITH
ADAMS
23.)waqtfo all the enames working in same job as smith ?
SQL> select ename from emp where job=(select job from emp where
ename='SMITH');
ENAME
----------
SMITH
ADAMS
JAMES
MILLER
24.)waqtfo all the enames getting a salary greater than smith ?
SQL> select ename from emp where sal> (select sal from emp where
ename='SMITH');
ENAME
----------
KING
BLAKE
CLARK
JONES
SCOTT
FORD
ALLEN
WARD
MARTIN
TURNER
ADAMS
JAMES
MILLER
13 rows selected.
25.)waqtfo all the enames getting a salary greater than all of clerks ?
SQL> select ename from emp where sal> all (select sal from emp where
job='CLERK');
ENAME
----------
TURNER
ALLEN
CLARK
BLAKE
JONES
FORD
SCOTT
KING
8 rows selected.
26.)waqtfo all the enames getting a salary greater than any one of the
clerks ?
SQL> select ename from emp where sal> any (select sal from emp where
job='CLERK');
ENAME
----------
KING
SCOTT
FORD
JONES
BLAKE
CLARK
ALLEN
TURNER
MILLER
MARTIN
WARD
ADAMS
JAMES
13 rows selected.
27.)waqtfo all the enames who is working in scotts dept or smith dept ?
SQL> select ename from emp where deptno= any (select deptno from emp where
ename in ('SCOTT','SMITH'));
ENAME
----------
ADAMS
SMITH
FORD
SCOTT
JONES
28.)waqtfo all the enames who is working NEW YORK ?
SQL> select ename from emp where deptno in (select deptno from dept where
loc='NEW YORK');
ENAME
----------
KING
CLARK
MILLER
29.)waqtfo all the enames working in RESEARCH dept ?
SQL> select ename from emp where deptno in (select deptno from dept where
dname='RESEARCH');
ENAME
----------
JONES
SCOTT
FORD
SMITH
ADAMS
30.)waqtfo all the enames who are working as CLERK in NEW YORK ?
SQL> select ename from emp where deptno in (select deptno from dept where
loc='NEW YORK' and job='CLERK');
ENAME
----------
MILLER
31.)waqtfo all the enames whose name is beginning with S ?
SQL> select ename from emp where ename like 'S%';
ENAME
----------
SCOTT
SMITH
32.)waqtfo all the enames starting with S and ending with H ?
SQL> select ename from emp where ename like 'S%H';
ENAME
----------
SMITH
33.)waqtfo all the enames which contains 3 letters ?
SQL> SQL> select ename from emp where ename like'___%';
ENAME
----------
KING
BLAKE
CLARK
JONES
SCOTT
FORD
SMITH
ALLEN
WARD
MARTIN
TURNER
ADAMS
JAMES
MILLER
14 rows selected.
34.)waqtfo all the enames which contains minimum of 3 letters and contains
I as its second last one ?
SQL> select ename from emp where ename like '___%' and ename like '%I_';
ENAME
----------
MARTIN
35.)waqtfo all the enames which contains M or N and it contains minimum of
4 letters and maximum of 6 letter and second letter should be either L or
Z ?
SQL> select ename from emp where ename like '___%' and (ename like '%M%'
or ename like '%N%') and (ename like '_L%' or ename like '_Z%') and (ename
like '___%' or ename like '______%');
ENAME
----------
ALLEN
36.)waqtfo all the enames which contains M ?
SQL> select ename from emp where lower(ename) like '%m%';
ENAME
----------
SMITH
MARTIN
ADAMS
JAMES
MILLER
37.)waqtfo the average salary of the emp table ?
SQL> select avg(sal) from emp;
AVG(SAL)
----------
2073.21429
38.)waqtfo the average salary of deptno 10 ?
SQL> select avg(sal) from emp where deptno=10;
AVG(SAL)
----------
2916.66667
39.)waqtfo the average salary of scotts dept ?
SQL> select avg(sal) from emp where deptno in (select deptno from emp
where ename='SCOTT');
AVG(SAL)
----------
2175
40.)waqtfo the average of each dept in the emp table ?
SQL> select avg(sal), deptno from emp group by deptno;
AVG(SAL) DEPTNO
---------- ----------
1566.66667 30
2175 20
2916.66667 10
41.)waqtfo the average salary of each job ?
SQL> select avg(sal), job from emp group by job;
AVG(SAL) JOB
---------- ---------
1037.5 CLERK
1400 SALESMAN
5000 PRESIDENT
2758.33333 MANAGER
3000 ANALYST
42.)waqtfo the average salary and no. of employees working in scotts
dept ?
SQL> select avg(sal), count(ename) from emp where deptno in (select deptno
from emp where ename='SCOTT');
AVG(SAL) COUNT(ENAME)
---------- ------------
2175 5
43.)waqtfo all the deptno and their corresponding average salary ?
SQL> select avg(sal), deptno from emp group by deptno;
AVG(SAL) DEPTNO
---------- ----------
1566.66667 30
2175 20
2916.66667 10
44.)waqtfo the maximum salary and minimum salary taken by each dept ?
SQL> select max(sal), min(sal), deptno from emp group by deptno;
MAX(SAL) MIN(SAL) DEPTNO
---------- ---------- ----------
2850 950 30
3000 800 20
5000 1300 10
45.)waqtfo the number of employees in each dept which is located either in
New York or Dallas ?
SQL> select count(empno), deptno from emp where deptno in (select deptno
from dept where loc ='NEW YORK' or loc='DALLAS') group by deptno;
COUNT(EMPNO) DEPTNO
------------ ----------
5 20
3 10
46.)waqtfo all the deptno. having an average salary greater than 2500 ?
SQL> select deptno, avg(sal) from emp group by deptno having avg(sal)
>2500;
DEPTNO AVG(SAL)
---------- ----------
10 2916.66667
47.)waqtfo the dept where are more than 3 employees ?
SQL> select deptno from emp group by deptno having count(empno) > 3;
DEPTNO
----------
30
20
48.)waqtfo all employee table and dept table ?
SQL> select emp.*, dept.* from emp, dept where emp.deptno=dept.deptno;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
DNAME LOC
-------------- -------------
7839 KING PRESIDENT 17-NOV-81 5000 10 10
ACCOUNTING NEW YORK
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 30
SALES CHICAGO
7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10
ACCOUNTING NEW YORK
7566 JONES MANAGER 7839 02-APR-81 2975 20 20
RESEARCH DALLAS
7788 SCOTT ANALYST 7566 19-APR-87 3000 20 20
RESEARCH DALLAS
7902 FORD ANALYST 7566 03-DEC-81 3000 20 20
RESEARCH DALLAS
7369 SMITH CLERK 7902 17-DEC-80 800 20 20
RESEARCH DALLAS
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 30
SALES CHICAGO
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 30
SALES CHICAGO
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 30
SALES CHICAGO
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 30
SALES CHICAGO
7876 ADAMS CLERK 7788 23-MAY-87 1100 20 20
RESEARCH DALLAS
7900 JAMES CLERK 7698 03-DEC-81 950 30 30
SALES CHICAGO
7934 MILLER CLERK 7782 23-JAN-82 1300 10 10
ACCOUNTING NEW YORK
14 rows selected.
49.)waqtfo all the enames and deptname ?
SQL> select emp.ename, dept.dname from emp, dept where
emp.deptno=dept.deptno;
ENAME DNAME
---------- --------------
KING ACCOUNTING
BLAKE SALES
CLARK ACCOUNTING
JONES RESEARCH
SCOTT RESEARCH
FORD RESEARCH
SMITH RESEARCH
ALLEN SALES
WARD SALES
MARTIN SALES
TURNER SALES
ADAMS RESEARCH
JAMES SALES
MILLER ACCOUNTING
14 rows selected.
50.)waqtfo all the employee name and dept. name working in New York ?
SQL> select emp.ename, dept.dname from emp, dept where
emp.deptno=dept.deptno and dept.loc='NEW YORK';
ENAME DNAME
---------- --------------
KING ACCOUNTING
CLARK ACCOUNTING
MILLER ACCOUNTING
51.)waqtfo all the employee names and dept. names working in SCOTTs
dept. ?
SQL> select emp.ename, dept.dname from emp, dept where
emp.deptno=dept.deptno and dept.deptno in (select deptno from emp where
ename='SCOTT');
ENAME DNAME
---------- --------------
JONES RESEARCH
SCOTT RESEARCH
FORD RESEARCH
SMITH RESEARCH
ADAMS RESEARCH
52.)waqtfo the dept.names and there average salary ?
SQL> select avg(emp.sal), dept.dname from emp, dept where
emp.deptno=dept.deptno group by dept.dname;
AVG(EMP.SAL) DNAME
------------ --------------
2916.66667 ACCOUNTING
2175 RESEARCH
1566.66667 SALES
53.)waqtfo all the employee table and dept. table ?
SQL> select emp.*, dept.* from emp, dept where emp.deptno(+)=dept.deptno;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
DNAME LOC
-------------- -------------
7839 KING PRESIDENT 17-NOV-81 5000 10 10
ACCOUNTING NEW YORK
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 30
SALES CHICAGO
7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10
ACCOUNTING NEW YORK
7566 JONES MANAGER 7839 02-APR-81 2975 20 20
RESEARCH DALLAS
7788 SCOTT ANALYST 7566 19-APR-87 3000 20 20
RESEARCH DALLAS
7902 FORD ANALYST 7566 03-DEC-81 3000 20 20
RESEARCH DALLAS
7369 SMITH CLERK 7902 17-DEC-80 800 20 20
RESEARCH DALLAS
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 30
SALES CHICAGO
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 30
SALES CHICAGO
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 30
SALES CHICAGO
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 30
SALES CHICAGO
7876 ADAMS CLERK 7788 23-MAY-87 1100 20 20
RESEARCH DALLAS
7900 JAMES CLERK 7698 03-DEC-81 950 30 30
SALES CHICAGO
7934 MILLER CLERK 7782 23-JAN-82 1300 10 10
ACCOUNTING NEW YORK
40
OPERATIONS BOSTON
15 rows selected.
54.)waqtfo all the employee table and dept. table ?
SQL> select emp.*, dept.* from emp, dept where emp.deptno=dept.deptno(+);
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
DNAME LOC
-------------- -------------
7934 MILLER CLERK 7782 23-JAN-82 1300 10 10
ACCOUNTING NEW YORK
7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10
ACCOUNTING NEW YORK
7839 KING PRESIDENT 17-NOV-81 5000 10 10
ACCOUNTING NEW YORK
7876 ADAMS CLERK 7788 23-MAY-87 1100 20 20
RESEARCH DALLAS
7369 SMITH CLERK 7902 17-DEC-80 800 20 20
RESEARCH DALLAS
7902 FORD ANALYST 7566 03-DEC-81 3000 20 20
RESEARCH DALLAS
7788 SCOTT ANALYST 7566 19-APR-87 3000 20 20
RESEARCH DALLAS
7566 JONES MANAGER 7839 02-APR-81 2975 20 20
RESEARCH DALLAS
7900 JAMES CLERK 7698 03-DEC-81 950 30 30
SALES CHICAGO
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 30
SALES CHICAGO
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 30
SALES CHICAGO
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 30
SALES CHICAGO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 30
SALES CHICAGO
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 30
SALES CHICAGO
14 rows selected.
55.)waqtfo all the employee names and dept. names, it should also include
those deptnames where there are no employees ?
SQL> select emp.ename, dept.dname from emp, dept where
emp.deptno(+)=dept.deptno;
ENAME DNAME
---------- --------------
KING ACCOUNTING
BLAKE SALES
CLARK ACCOUNTING
JONES RESEARCH
SCOTT RESEARCH
FORD RESEARCH
SMITH RESEARCH
ALLEN SALES
WARD SALES
MARTIN SALES
TURNER SALES
ADAMS RESEARCH
JAMES SALES
MILLER ACCOUNTING
OPERATIONS
15 rows selected.
56.)waqtfo all the dept.names were there are no employees ?
SQL> select emp.ename, dept.dname from emp, dept where
emp.deptno(+)=dept.deptno and emp.deptno is null;
ENAME DNAME
---------- --------------
OPERATIONS
57.)waqtfo all the dept.names and there average salary ?
SQL> select avg(emp.sal), dept.dname from emp, dept where
emp.deptno(+)=dept.deptno group by dname;
AVG(EMP.SAL) DNAME
------------ --------------
2916.66667 ACCOUNTING
OPERATIONS
2175 RESEARCH
1566.66667 SALES
58.)waqtfo the number of employee in each dept. ?
SQL> select count(emp.ename), dept.deptno from emp, dept where
emp.deptno(+)=dept.deptno group by dept.deptno;
COUNT(EMP.ENAME) DEPTNO
---------------- ----------
3 10
5 20
6 30
0 40
59.)waqtfo all employees names and manager names ?
SQL> select e1.ename, e2.ename as mgr_name from emp e1, emp e2 where
e1.mgr=e2.empno;
ENAME MGR_NAME
---------- ----------
JONES KING
CLARK KING
BLAKE KING
JAMES BLAKE
TURNER BLAKE
MARTIN BLAKE
WARD BLAKE
ALLEN BLAKE
MILLER CLARK
FORD JONES
SCOTT JONES
ADAMS SCOTT
SMITH FORD
13 rows selected.
60.)write an update statement to update all the employee salary by
Rs.100 ?
SQL> update emp set sal=sal+100 where empno is not null;
14 rows updated.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7839 KING PRESIDENT 17-NOV-81 5100 10
7698 BLAKE MANAGER 7839 01-MAY-81 2950 30
7782 CLARK MANAGER 7839 09-JUN-81 2550 10
7566 JONES MANAGER 7839 02-APR-81 3075 20
7788 SCOTT ANALYST 7566 19-APR-87 3100 20
7902 FORD ANALYST 7566 03-DEC-81 3100 20
7369 SMITH CLERK 7902 17-DEC-80 900 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30
7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1200 20
7900 JAMES CLERK 7698 03-DEC-81 1050 30
7934 MILLER CLERK 7782 23-JAN-82 1400 10
14 rows selected.
61.)write an update statement to update all the job from clerk to FDA ?
SQL> update emp set job='FDA' where job='CLERK';
4 rows updated.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7839 KING PRESIDENT 17-NOV-81 5100 10
7698 BLAKE MANAGER 7839 01-MAY-81 2950 30
7782 CLARK MANAGER 7839 09-JUN-81 2550 10
7566 JONES MANAGER 7839 02-APR-81 3075 20
7788 SCOTT ANALYST 7566 19-APR-87 3100 20
7902 FORD ANALYST 7566 03-DEC-81 3100 20
7369 SMITH FDA 7902 17-DEC-80 900 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30
7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30
7876 ADAMS FDA 7788 23-MAY-87 1200 20
7900 JAMES FDA 7698 03-DEC-81 1050 30
7934 MILLER FDA 7782 23-JAN-82 1400 10
14 rows selected.
62.)write an update statement to update al the manager sal to Rs.100 who
are working in New York ?
SQL> update emp set sal=sal+100 where job='MANAGER' and deptno in (select
deptno from dept where loc='NEW YORK');
1 row updated.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7839 KING PRESIDENT 17-NOV-81 5100 10
7698 BLAKE MANAGER 7839 01-MAY-81 2950 30
7782 CLARK MANAGER 7839 09-JUN-81 2650 10
7566 JONES MANAGER 7839 02-APR-81 3075 20
7788 SCOTT ANALYST 7566 19-APR-87 3100 20
7902 FORD ANALYST 7566 03-DEC-81 3100 20
7369 SMITH FDA 7902 17-DEC-80 900 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30
7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30
7876 ADAMS FDA 7788 23-MAY-87 1200 20
7900 JAMES FDA 7698 03-DEC-81 1050 30
7934 MILLER FDA 7782 23-JAN-82 1400 10
14 rows selected.
SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
63.)write a delete statement to delete all the employee records who are
working as manager ?
SQL> delete from emp where job='MANAGER';
3 rows deleted.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7839 KING PRESIDENT 17-NOV-81 5100 10
7788 SCOTT ANALYST 7566 19-APR-87 3100 20
7902 FORD ANALYST 7566 03-DEC-81 3100 20
7369 SMITH FDA 7902 17-DEC-80 900 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30
7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30
7876 ADAMS FDA 7788 23-MAY-87 1200 20
7900 JAMES FDA 7698 03-DEC-81 1050 30
7934 MILLER FDA 7782 23-JAN-82 1400 10
11 rows selected.
64.)write a delete statement to delete all the employee records who are
working with New York ?
SQL> delete from emp where deptno in (select deptno from dept where
loc='NEW YORK');
2 rows deleted.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7788 SCOTT ANALYST 7566 19-APR-87 3100 20
7902 FORD ANALYST 7566 03-DEC-81 3100 20
7369 SMITH FDA 7902 17-DEC-80 900 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30
7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30
7876 ADAMS FDA 7788 23-MAY-87 1200 20
7900 JAMES FDA 7698 03-DEC-81 1050 30
9 rows selected.
65.)write a delete statement to delete all the employee who are working in
SCOTTs dept. as managers and getting a salary greater than the average
salary of a clerk ?
SQL> delete from emp where deptno in (select deptno from emp where
ename='SCOTT' and job='MANAGER') and sal > (select avg(sal) from emp where
job='CLERK');
0 rows deleted.

More Related Content

What's hot

DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaMohammad Imam Hossain
Β 
Sql task
Sql taskSql task
Sql taskNawaz Sk
Β 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions setMohd Tousif
Β 
Sql queries questions and answers
Sql queries questions and answersSql queries questions and answers
Sql queries questions and answersMichael Belete
Β 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answersvijaybusu
Β 
SQL practice questions - set 3
SQL practice questions - set 3SQL practice questions - set 3
SQL practice questions - set 3Mohd Tousif
Β 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handoutsjhe04
Β 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Achmad Solichin
Β 
Sub query_SQL
Sub query_SQLSub query_SQL
Sub query_SQLCoT
Β 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesMohammad Imam Hossain
Β 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
Β 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideSrinimf-Slides
Β 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Achmad Solichin
Β 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Punjab University
Β 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Sanjay Pathak
Β 

What's hot (20)

DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR Schema
Β 
Sql queires
Sql queiresSql queires
Sql queires
Β 
Sql task
Sql taskSql task
Sql task
Β 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions set
Β 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
Β 
Sql queries questions and answers
Sql queries questions and answersSql queries questions and answers
Sql queries questions and answers
Β 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
Β 
SQL practice questions - set 3
SQL practice questions - set 3SQL practice questions - set 3
SQL practice questions - set 3
Β 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
Β 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
Β 
Sub query_SQL
Sub query_SQLSub query_SQL
Sub query_SQL
Β 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related Queries
Β 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Β 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Β 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
Β 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Β 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
Β 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
Β 
Sql join
Sql  joinSql  join
Sql join
Β 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)
Β 

Similar to 80 different SQL Queries with output

SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2Umair Amjad
Β 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013Connor McDonald
Β 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
Β 
Les02
Les02Les02
Les02jsgcruz
Β 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02Angel G Diaz
Β 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Datasiavosh kaviani
Β 
Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„
Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„
Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„Mohamed Moustafa
Β 
Les02.pptx
Les02.pptxLes02.pptx
Les02.pptxNishaTariq1
Β 
Restricting and sorting data
Restricting and sorting data Restricting and sorting data
Restricting and sorting data HuzaifaMushtaq3
Β 
chap2 (3).ppt
chap2 (3).pptchap2 (3).ppt
chap2 (3).ppteemantariq2
Β 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
Β 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oraclesuman1248
Β 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchiesConnor McDonald
Β 

Similar to 80 different SQL Queries with output (20)

Sql2
Sql2Sql2
Sql2
Β 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
Β 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
Β 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
Β 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
Β 
Les02
Les02Les02
Les02
Β 
Les02
Les02Les02
Les02
Β 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
Β 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Data
Β 
Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„
Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„
Ψ­Ω„ Ψ§Ψ³Ψ¦Ω„Ψ© Ψ§Ω„ΩƒΨͺΨ§Ψ¨ Ψ§Ω„Ψ³ΨΉΩˆΨ―Ω‰ فى Ψ΄Ψ±Ψ­ Ω‚ΩˆΨ§ΨΉΨ― Ψ§Ω„Ψ¨ΩŠΨ§Ω†Ψ§Ψͺ Ψ§ΩˆΨ±Ψ§ΩƒΩ„
Β 
Les02.pptx
Les02.pptxLes02.pptx
Les02.pptx
Β 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
Β 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
Β 
Restricting and sorting data
Restricting and sorting data Restricting and sorting data
Restricting and sorting data
Β 
chap2 (3).ppt
chap2 (3).pptchap2 (3).ppt
chap2 (3).ppt
Β 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
Β 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
Β 
Les01
Les01Les01
Les01
Β 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchies
Β 
Les01
Les01Les01
Les01
Β 

More from Nexus

64 interview questions
64 interview questions64 interview questions
64 interview questionsNexus
Β 
Pl sql student guide v 4
Pl sql student guide v 4Pl sql student guide v 4
Pl sql student guide v 4Nexus
Β 
Pl sql student guide v 3
Pl sql student guide v 3Pl sql student guide v 3
Pl sql student guide v 3Nexus
Β 
Pl sql student guide v 1
Pl sql student guide v 1Pl sql student guide v 1
Pl sql student guide v 1Nexus
Β 
Java basics notes
Java basics notesJava basics notes
Java basics notesNexus
Β 
Lecture notes 2(Electrical machine-1)
Lecture notes 2(Electrical machine-1)Lecture notes 2(Electrical machine-1)
Lecture notes 2(Electrical machine-1)Nexus
Β 
module 3 (Mechanics)
module 3 (Mechanics)module 3 (Mechanics)
module 3 (Mechanics)Nexus
Β 
module 2 (Mechanics)
module 2 (Mechanics)module 2 (Mechanics)
module 2 (Mechanics)Nexus
Β 
module 1 (Mechanics)
module 1 (Mechanics)module 1 (Mechanics)
module 1 (Mechanics)Nexus
Β 
Engineering physics
Engineering physicsEngineering physics
Engineering physicsNexus
Β 
Engineering physics 9(doped or extrindic semiconductors)
Engineering physics 9(doped or extrindic semiconductors)Engineering physics 9(doped or extrindic semiconductors)
Engineering physics 9(doped or extrindic semiconductors)Nexus
Β 
Engineering physics 8(semiconductors)
Engineering physics 8(semiconductors)Engineering physics 8(semiconductors)
Engineering physics 8(semiconductors)Nexus
Β 
Engineering physics 7(conductors, insulators and semiconductors)
Engineering physics 7(conductors, insulators and semiconductors)Engineering physics 7(conductors, insulators and semiconductors)
Engineering physics 7(conductors, insulators and semiconductors)Nexus
Β 
Engineering physics 6(Band theory of solids)
Engineering physics 6(Band theory of solids)Engineering physics 6(Band theory of solids)
Engineering physics 6(Band theory of solids)Nexus
Β 
Engineering physics 5(Quantum free electron theory)
Engineering physics 5(Quantum free electron theory)Engineering physics 5(Quantum free electron theory)
Engineering physics 5(Quantum free electron theory)Nexus
Β 
Engineering physics 4(Thermal conductivity)
Engineering physics 4(Thermal conductivity)Engineering physics 4(Thermal conductivity)
Engineering physics 4(Thermal conductivity)Nexus
Β 
Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...
Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...
Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...Nexus
Β 
Engineering physics 2(Electron Theory of metals)
Engineering physics 2(Electron Theory of metals)Engineering physics 2(Electron Theory of metals)
Engineering physics 2(Electron Theory of metals)Nexus
Β 
Engineering physics 1(Electrical conductivity)
Engineering physics 1(Electrical conductivity)Engineering physics 1(Electrical conductivity)
Engineering physics 1(Electrical conductivity)Nexus
Β 
Engineering physics-Questions
Engineering physics-QuestionsEngineering physics-Questions
Engineering physics-QuestionsNexus
Β 

More from Nexus (20)

64 interview questions
64 interview questions64 interview questions
64 interview questions
Β 
Pl sql student guide v 4
Pl sql student guide v 4Pl sql student guide v 4
Pl sql student guide v 4
Β 
Pl sql student guide v 3
Pl sql student guide v 3Pl sql student guide v 3
Pl sql student guide v 3
Β 
Pl sql student guide v 1
Pl sql student guide v 1Pl sql student guide v 1
Pl sql student guide v 1
Β 
Java basics notes
Java basics notesJava basics notes
Java basics notes
Β 
Lecture notes 2(Electrical machine-1)
Lecture notes 2(Electrical machine-1)Lecture notes 2(Electrical machine-1)
Lecture notes 2(Electrical machine-1)
Β 
module 3 (Mechanics)
module 3 (Mechanics)module 3 (Mechanics)
module 3 (Mechanics)
Β 
module 2 (Mechanics)
module 2 (Mechanics)module 2 (Mechanics)
module 2 (Mechanics)
Β 
module 1 (Mechanics)
module 1 (Mechanics)module 1 (Mechanics)
module 1 (Mechanics)
Β 
Engineering physics
Engineering physicsEngineering physics
Engineering physics
Β 
Engineering physics 9(doped or extrindic semiconductors)
Engineering physics 9(doped or extrindic semiconductors)Engineering physics 9(doped or extrindic semiconductors)
Engineering physics 9(doped or extrindic semiconductors)
Β 
Engineering physics 8(semiconductors)
Engineering physics 8(semiconductors)Engineering physics 8(semiconductors)
Engineering physics 8(semiconductors)
Β 
Engineering physics 7(conductors, insulators and semiconductors)
Engineering physics 7(conductors, insulators and semiconductors)Engineering physics 7(conductors, insulators and semiconductors)
Engineering physics 7(conductors, insulators and semiconductors)
Β 
Engineering physics 6(Band theory of solids)
Engineering physics 6(Band theory of solids)Engineering physics 6(Band theory of solids)
Engineering physics 6(Band theory of solids)
Β 
Engineering physics 5(Quantum free electron theory)
Engineering physics 5(Quantum free electron theory)Engineering physics 5(Quantum free electron theory)
Engineering physics 5(Quantum free electron theory)
Β 
Engineering physics 4(Thermal conductivity)
Engineering physics 4(Thermal conductivity)Engineering physics 4(Thermal conductivity)
Engineering physics 4(Thermal conductivity)
Β 
Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...
Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...
Engineering physics 3(Relaxation time, Temperature dependence of Electrical R...
Β 
Engineering physics 2(Electron Theory of metals)
Engineering physics 2(Electron Theory of metals)Engineering physics 2(Electron Theory of metals)
Engineering physics 2(Electron Theory of metals)
Β 
Engineering physics 1(Electrical conductivity)
Engineering physics 1(Electrical conductivity)Engineering physics 1(Electrical conductivity)
Engineering physics 1(Electrical conductivity)
Β 
Engineering physics-Questions
Engineering physics-QuestionsEngineering physics-Questions
Engineering physics-Questions
Β 

Recently uploaded

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
Β 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
Β 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
Β 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
Β 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
Β 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
Β 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
Β 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
Β 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
Β 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
Β 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
Β 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
Β 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
Β 
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈcall girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ9953056974 Low Rate Call Girls In Saket, Delhi NCR
Β 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
Β 

Recently uploaded (20)

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
Β 
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Β 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Β 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
Β 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
Β 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
Β 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
Β 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
Β 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
Β 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
Β 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
Β 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
Β 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
Β 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
Β 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
Β 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
Β 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
Β 
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈcall girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
call girls in Kamla Market (DELHI) πŸ” >ΰΌ’9953330565πŸ” genuine Escort Service πŸ”βœ”οΈβœ”οΈ
Β 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
Β 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
Β 

80 different SQL Queries with output

  • 1. 1.)waqtfo all the list of tables ? SQL> select * from cat; TABLE_NAME TABLE_TYPE ------------------------------ ----------- BONUS TABLE DEPT TABLE EMP TABLE SALGRADE TABLE 2.)waqtfo all the dept details ? SQL> select * from dept; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 3.)waqtfo the deptno from dept table ? SQL> select deptno from dept; DEPTNO ---------- 10 20 30 40 4.)waqtfo location and deptno from dept ? SQL> select deptno, loc from dept; DEPTNO LOC ---------- ------------- 10 NEW YORK 20 DALLAS 30 CHICAGO
  • 2. 40 BOSTON 5.)waqtfo all the dept details ? SQL> select * from dept; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 6.)waqtfo all the dept name and deptno from the dept table ? SQL> select dname, deptno from dept; DNAME DEPTNO -------------- ---------- ACCOUNTING 10 RESEARCH 20 SALES 30 OPERATIONS 40 7.)waqtfo all the employee names and their corresponding salary ? SQL> select ename, sal from emp; ENAME SAL ---------- ---------- KING 5000 BLAKE 2850 CLARK 2450 JONES 2975 SCOTT 3000 FORD 3000 SMITH 800 ALLEN 1600 WARD 1250 MARTIN 1250 TURNER 1500 ADAMS 1100 JAMES 950 MILLER 1300
  • 3. 14 rows selected. 8.)waqtfo all the employee names and their job and salary ? SQL> select ename, sal, job from emp; ENAME SAL JOB ---------- ---------- --------- KING 5000 PRESIDENT BLAKE 2850 MANAGER CLARK 2450 MANAGER JONES 2975 MANAGER SCOTT 3000 ANALYST FORD 3000 ANALYST SMITH 800 CLERK ALLEN 1600 SALESMAN WARD 1250 SALESMAN MARTIN 1250 SALESMAN TURNER 1500 SALESMAN ADAMS 1100 CLERK JAMES 950 CLERK MILLER 1300 CLERK 14 rows selected. 9.)waqtfo all the employee names, salary and annual salary ? SQL> select ename, sal, sal*12 from emp; ENAME SAL SAL*12 ---------- ---------- ---------- KING 5000 60000 BLAKE 2850 34200 CLARK 2450 29400 JONES 2975 35700 SCOTT 3000 36000 FORD 3000 36000 SMITH 800 9600 ALLEN 1600 19200 WARD 1250 15000 MARTIN 1250 15000 TURNER 1500 18000 ADAMS 1100 13200 JAMES 950 11400 MILLER 1300 15600 14 rows selected.
  • 4. 10.)waqtfo all the employee names, salary, annual salary and projected annual salary, if it is increased by 11% ? SQL> select ename, sal, sal*12, sal*12*1.11 from emp; ENAME SAL SAL*12 SAL*12*1.11 ---------- ---------- ---------- ----------- KING 5000 60000 66600 BLAKE 2850 34200 37962 CLARK 2450 29400 32634 JONES 2975 35700 39627 SCOTT 3000 36000 39960 FORD 3000 36000 39960 SMITH 800 9600 10656 ALLEN 1600 19200 21312 WARD 1250 15000 16650 MARTIN 1250 15000 16650 TURNER 1500 18000 19980 ADAMS 1100 13200 14652 JAMES 950 11400 12654 MILLER 1300 15600 17316 14 rows selected. 11.)waqtfo all the employee names, salary, annual salary and projected annual salary, if it is increased by 11% using Alias keyword ? SQL> select ename as emp_name, sal, sal*12, sal*12*1.11 as projected from emp; EMP_NAME SAL SAL*12 PROJECTED ---------- ---------- ---------- ---------- KING 5000 60000 66600 BLAKE 2850 34200 37962 CLARK 2450 29400 32634 JONES 2975 35700 39627 SCOTT 3000 36000 39960 FORD 3000 36000 39960 SMITH 800 9600 10656 ALLEN 1600 19200 21312 WARD 1250 15000 16650 MARTIN 1250 15000 16650 TURNER 1500 18000 19980 ADAMS 1100 13200 14652 JAMES 950 11400 12654 MILLER 1300 15600 17316 14 rows selected.
  • 5. 12.)waqtfo available deptno in emp table ? SQL> select distinct deptno from emp; DEPTNO ---------- 30 20 10 13.)waqtfo all the employee names and employee no from emp using concatenation alias keyword ? SQL> select 'my name is .....'||ename||' '||empno as myname from emp; MYNAME ------------------------------------------------------------------- my name is .....KING 7839 my name is .....BLAKE 7698 my name is .....CLARK 7782 my name is .....JONES 7566 my name is .....SCOTT 7788 my name is .....FORD 7902 my name is .....SMITH 7369 my name is .....ALLEN 7499 my name is .....WARD 7521 my name is .....MARTIN 7654 my name is .....TURNER 7844 my name is .....ADAMS 7876 my name is .....JAMES 7900 my name is .....MILLER 7934 14 rows selected. 14.)waqtfo all the employee names who belong to deptno 10 ? SQL> select ename from emp where deptno=10; ENAME ---------- KING CLARK MILLER 15.)waqtfo all the employee names who is getting the salary greater than 1000 and lesser than 3000 ?
  • 6. SQL> select ename from emp where sal>1000 and sal<3000; ENAME ---------- BLAKE CLARK JONES ALLEN WARD MARTIN TURNER ADAMS MILLER 9 rows selected. 16.)waqtfo all the employee names who are working as CLERK ? SQL> select ename from emp where job='CLERK'; ENAME ---------- SMITH ADAMS JAMES MILLER 17.)waqtfo all the employee names have salary greater than 1000 lesser than 3000 and working as either CLERK, SALESMAN or ANALYSIST and working in a deptno 10,20 or 30 ? SQL> select ename from emp where (sal>1000 and sal<3000) and (job='CLERK' or job='SALESMAN' or job='ANALYST') and (deptno=10 or deptno=20 or deptno=30); ENAME ---------- ALLEN WARD MARTIN TURNER ADAMS MILLER 6 rows selected. 18.)waqtfo all the employee names working in deptno 10 or 20 or 30 or 40 ?
  • 7. SQL> select ename from emp where deptno in (10,20,30,40); ENAME ---------- KING BLAKE CLARK JONES SCOTT FORD SMITH ALLEN WARD MARTIN TURNER ADAMS JAMES MILLER 14 rows selected. 19.)waqtfo all the enames who are eligible for commision ? SQL> select ename from emp where comm is not null; ENAME ---------- ALLEN WARD MARTIN TURNER 20.)waqtfo all the enames having managers ? SQL> select ename from emp where MGR is not null; ENAME ---------- BLAKE CLARK JONES SCOTT FORD SMITH ALLEN WARD
  • 8. MARTIN TURNER ADAMS JAMES MILLER 13 rows selected. 21.)waqtfo all the enames who are working in deptno 10 ? SQL> select ename from emp where deptno=10; ENAME ---------- KING CLARK MILLER 22.)waqtfo all the enames working in scott's dept ? SQL> select ename from emp where deptno=(select deptno from emp where ename='SCOTT'); ENAME ---------- JONES SCOTT FORD SMITH ADAMS 23.)waqtfo all the enames working in same job as smith ? SQL> select ename from emp where job=(select job from emp where ename='SMITH'); ENAME ---------- SMITH ADAMS JAMES MILLER 24.)waqtfo all the enames getting a salary greater than smith ?
  • 9. SQL> select ename from emp where sal> (select sal from emp where ename='SMITH'); ENAME ---------- KING BLAKE CLARK JONES SCOTT FORD ALLEN WARD MARTIN TURNER ADAMS JAMES MILLER 13 rows selected. 25.)waqtfo all the enames getting a salary greater than all of clerks ? SQL> select ename from emp where sal> all (select sal from emp where job='CLERK'); ENAME ---------- TURNER ALLEN CLARK BLAKE JONES FORD SCOTT KING 8 rows selected. 26.)waqtfo all the enames getting a salary greater than any one of the clerks ? SQL> select ename from emp where sal> any (select sal from emp where job='CLERK'); ENAME ----------
  • 10. KING SCOTT FORD JONES BLAKE CLARK ALLEN TURNER MILLER MARTIN WARD ADAMS JAMES 13 rows selected. 27.)waqtfo all the enames who is working in scotts dept or smith dept ? SQL> select ename from emp where deptno= any (select deptno from emp where ename in ('SCOTT','SMITH')); ENAME ---------- ADAMS SMITH FORD SCOTT JONES 28.)waqtfo all the enames who is working NEW YORK ? SQL> select ename from emp where deptno in (select deptno from dept where loc='NEW YORK'); ENAME ---------- KING CLARK MILLER 29.)waqtfo all the enames working in RESEARCH dept ? SQL> select ename from emp where deptno in (select deptno from dept where dname='RESEARCH');
  • 11. ENAME ---------- JONES SCOTT FORD SMITH ADAMS 30.)waqtfo all the enames who are working as CLERK in NEW YORK ? SQL> select ename from emp where deptno in (select deptno from dept where loc='NEW YORK' and job='CLERK'); ENAME ---------- MILLER 31.)waqtfo all the enames whose name is beginning with S ? SQL> select ename from emp where ename like 'S%'; ENAME ---------- SCOTT SMITH 32.)waqtfo all the enames starting with S and ending with H ? SQL> select ename from emp where ename like 'S%H'; ENAME ---------- SMITH 33.)waqtfo all the enames which contains 3 letters ? SQL> SQL> select ename from emp where ename like'___%'; ENAME ---------- KING BLAKE CLARK JONES SCOTT
  • 12. FORD SMITH ALLEN WARD MARTIN TURNER ADAMS JAMES MILLER 14 rows selected. 34.)waqtfo all the enames which contains minimum of 3 letters and contains I as its second last one ? SQL> select ename from emp where ename like '___%' and ename like '%I_'; ENAME ---------- MARTIN 35.)waqtfo all the enames which contains M or N and it contains minimum of 4 letters and maximum of 6 letter and second letter should be either L or Z ? SQL> select ename from emp where ename like '___%' and (ename like '%M%' or ename like '%N%') and (ename like '_L%' or ename like '_Z%') and (ename like '___%' or ename like '______%'); ENAME ---------- ALLEN 36.)waqtfo all the enames which contains M ? SQL> select ename from emp where lower(ename) like '%m%'; ENAME ---------- SMITH MARTIN ADAMS JAMES MILLER 37.)waqtfo the average salary of the emp table ?
  • 13. SQL> select avg(sal) from emp; AVG(SAL) ---------- 2073.21429 38.)waqtfo the average salary of deptno 10 ? SQL> select avg(sal) from emp where deptno=10; AVG(SAL) ---------- 2916.66667 39.)waqtfo the average salary of scotts dept ? SQL> select avg(sal) from emp where deptno in (select deptno from emp where ename='SCOTT'); AVG(SAL) ---------- 2175 40.)waqtfo the average of each dept in the emp table ? SQL> select avg(sal), deptno from emp group by deptno; AVG(SAL) DEPTNO ---------- ---------- 1566.66667 30 2175 20 2916.66667 10 41.)waqtfo the average salary of each job ? SQL> select avg(sal), job from emp group by job; AVG(SAL) JOB ---------- --------- 1037.5 CLERK 1400 SALESMAN 5000 PRESIDENT
  • 14. 2758.33333 MANAGER 3000 ANALYST 42.)waqtfo the average salary and no. of employees working in scotts dept ? SQL> select avg(sal), count(ename) from emp where deptno in (select deptno from emp where ename='SCOTT'); AVG(SAL) COUNT(ENAME) ---------- ------------ 2175 5 43.)waqtfo all the deptno and their corresponding average salary ? SQL> select avg(sal), deptno from emp group by deptno; AVG(SAL) DEPTNO ---------- ---------- 1566.66667 30 2175 20 2916.66667 10 44.)waqtfo the maximum salary and minimum salary taken by each dept ? SQL> select max(sal), min(sal), deptno from emp group by deptno; MAX(SAL) MIN(SAL) DEPTNO ---------- ---------- ---------- 2850 950 30 3000 800 20 5000 1300 10 45.)waqtfo the number of employees in each dept which is located either in New York or Dallas ? SQL> select count(empno), deptno from emp where deptno in (select deptno from dept where loc ='NEW YORK' or loc='DALLAS') group by deptno; COUNT(EMPNO) DEPTNO ------------ ---------- 5 20 3 10 46.)waqtfo all the deptno. having an average salary greater than 2500 ? SQL> select deptno, avg(sal) from emp group by deptno having avg(sal) >2500; DEPTNO AVG(SAL) ---------- ---------- 10 2916.66667 47.)waqtfo the dept where are more than 3 employees ?
  • 15. SQL> select deptno from emp group by deptno having count(empno) > 3; DEPTNO ---------- 30 20 48.)waqtfo all employee table and dept table ? SQL> select emp.*, dept.* from emp, dept where emp.deptno=dept.deptno; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ---------- DNAME LOC -------------- ------------- 7839 KING PRESIDENT 17-NOV-81 5000 10 10 ACCOUNTING NEW YORK 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 30 SALES CHICAGO 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10 ACCOUNTING NEW YORK 7566 JONES MANAGER 7839 02-APR-81 2975 20 20 RESEARCH DALLAS 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 20 RESEARCH DALLAS 7902 FORD ANALYST 7566 03-DEC-81 3000 20 20 RESEARCH DALLAS 7369 SMITH CLERK 7902 17-DEC-80 800 20 20 RESEARCH DALLAS 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 30 SALES CHICAGO 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 30 SALES CHICAGO 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 30 SALES CHICAGO 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 30 SALES CHICAGO 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 20 RESEARCH DALLAS 7900 JAMES CLERK 7698 03-DEC-81 950 30 30 SALES CHICAGO 7934 MILLER CLERK 7782 23-JAN-82 1300 10 10 ACCOUNTING NEW YORK 14 rows selected. 49.)waqtfo all the enames and deptname ? SQL> select emp.ename, dept.dname from emp, dept where emp.deptno=dept.deptno; ENAME DNAME ---------- -------------- KING ACCOUNTING BLAKE SALES CLARK ACCOUNTING
  • 16. JONES RESEARCH SCOTT RESEARCH FORD RESEARCH SMITH RESEARCH ALLEN SALES WARD SALES MARTIN SALES TURNER SALES ADAMS RESEARCH JAMES SALES MILLER ACCOUNTING 14 rows selected. 50.)waqtfo all the employee name and dept. name working in New York ? SQL> select emp.ename, dept.dname from emp, dept where emp.deptno=dept.deptno and dept.loc='NEW YORK'; ENAME DNAME ---------- -------------- KING ACCOUNTING CLARK ACCOUNTING MILLER ACCOUNTING 51.)waqtfo all the employee names and dept. names working in SCOTTs dept. ? SQL> select emp.ename, dept.dname from emp, dept where emp.deptno=dept.deptno and dept.deptno in (select deptno from emp where ename='SCOTT'); ENAME DNAME ---------- -------------- JONES RESEARCH SCOTT RESEARCH FORD RESEARCH SMITH RESEARCH ADAMS RESEARCH 52.)waqtfo the dept.names and there average salary ? SQL> select avg(emp.sal), dept.dname from emp, dept where emp.deptno=dept.deptno group by dept.dname; AVG(EMP.SAL) DNAME ------------ -------------- 2916.66667 ACCOUNTING 2175 RESEARCH 1566.66667 SALES 53.)waqtfo all the employee table and dept. table ? SQL> select emp.*, dept.* from emp, dept where emp.deptno(+)=dept.deptno; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ---------- DNAME LOC -------------- ------------- 7839 KING PRESIDENT 17-NOV-81 5000 10 10 ACCOUNTING NEW YORK
  • 17. 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 30 SALES CHICAGO 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10 ACCOUNTING NEW YORK 7566 JONES MANAGER 7839 02-APR-81 2975 20 20 RESEARCH DALLAS 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 20 RESEARCH DALLAS 7902 FORD ANALYST 7566 03-DEC-81 3000 20 20 RESEARCH DALLAS 7369 SMITH CLERK 7902 17-DEC-80 800 20 20 RESEARCH DALLAS 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 30 SALES CHICAGO 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 30 SALES CHICAGO 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 30 SALES CHICAGO 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 30 SALES CHICAGO 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 20 RESEARCH DALLAS 7900 JAMES CLERK 7698 03-DEC-81 950 30 30 SALES CHICAGO 7934 MILLER CLERK 7782 23-JAN-82 1300 10 10 ACCOUNTING NEW YORK 40 OPERATIONS BOSTON 15 rows selected. 54.)waqtfo all the employee table and dept. table ? SQL> select emp.*, dept.* from emp, dept where emp.deptno=dept.deptno(+); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ---------- DNAME LOC -------------- ------------- 7934 MILLER CLERK 7782 23-JAN-82 1300 10 10 ACCOUNTING NEW YORK 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10 ACCOUNTING NEW YORK 7839 KING PRESIDENT 17-NOV-81 5000 10 10 ACCOUNTING NEW YORK 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 20 RESEARCH DALLAS 7369 SMITH CLERK 7902 17-DEC-80 800 20 20 RESEARCH DALLAS 7902 FORD ANALYST 7566 03-DEC-81 3000 20 20 RESEARCH DALLAS 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 20 RESEARCH DALLAS 7566 JONES MANAGER 7839 02-APR-81 2975 20 20 RESEARCH DALLAS 7900 JAMES CLERK 7698 03-DEC-81 950 30 30 SALES CHICAGO
  • 18. 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 30 SALES CHICAGO 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 30 SALES CHICAGO 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 30 SALES CHICAGO 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 30 SALES CHICAGO 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 30 SALES CHICAGO 14 rows selected. 55.)waqtfo all the employee names and dept. names, it should also include those deptnames where there are no employees ? SQL> select emp.ename, dept.dname from emp, dept where emp.deptno(+)=dept.deptno; ENAME DNAME ---------- -------------- KING ACCOUNTING BLAKE SALES CLARK ACCOUNTING JONES RESEARCH SCOTT RESEARCH FORD RESEARCH SMITH RESEARCH ALLEN SALES WARD SALES MARTIN SALES TURNER SALES ADAMS RESEARCH JAMES SALES MILLER ACCOUNTING OPERATIONS 15 rows selected. 56.)waqtfo all the dept.names were there are no employees ? SQL> select emp.ename, dept.dname from emp, dept where emp.deptno(+)=dept.deptno and emp.deptno is null; ENAME DNAME ---------- -------------- OPERATIONS 57.)waqtfo all the dept.names and there average salary ? SQL> select avg(emp.sal), dept.dname from emp, dept where emp.deptno(+)=dept.deptno group by dname; AVG(EMP.SAL) DNAME ------------ -------------- 2916.66667 ACCOUNTING OPERATIONS 2175 RESEARCH
  • 19. 1566.66667 SALES 58.)waqtfo the number of employee in each dept. ? SQL> select count(emp.ename), dept.deptno from emp, dept where emp.deptno(+)=dept.deptno group by dept.deptno; COUNT(EMP.ENAME) DEPTNO ---------------- ---------- 3 10 5 20 6 30 0 40 59.)waqtfo all employees names and manager names ? SQL> select e1.ename, e2.ename as mgr_name from emp e1, emp e2 where e1.mgr=e2.empno; ENAME MGR_NAME ---------- ---------- JONES KING CLARK KING BLAKE KING JAMES BLAKE TURNER BLAKE MARTIN BLAKE WARD BLAKE ALLEN BLAKE MILLER CLARK FORD JONES SCOTT JONES ADAMS SCOTT SMITH FORD 13 rows selected. 60.)write an update statement to update all the employee salary by Rs.100 ? SQL> update emp set sal=sal+100 where empno is not null; 14 rows updated. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7839 KING PRESIDENT 17-NOV-81 5100 10 7698 BLAKE MANAGER 7839 01-MAY-81 2950 30 7782 CLARK MANAGER 7839 09-JUN-81 2550 10 7566 JONES MANAGER 7839 02-APR-81 3075 20 7788 SCOTT ANALYST 7566 19-APR-87 3100 20 7902 FORD ANALYST 7566 03-DEC-81 3100 20 7369 SMITH CLERK 7902 17-DEC-80 900 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30 7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30 7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1200 20
  • 20. 7900 JAMES CLERK 7698 03-DEC-81 1050 30 7934 MILLER CLERK 7782 23-JAN-82 1400 10 14 rows selected. 61.)write an update statement to update all the job from clerk to FDA ? SQL> update emp set job='FDA' where job='CLERK'; 4 rows updated. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7839 KING PRESIDENT 17-NOV-81 5100 10 7698 BLAKE MANAGER 7839 01-MAY-81 2950 30 7782 CLARK MANAGER 7839 09-JUN-81 2550 10 7566 JONES MANAGER 7839 02-APR-81 3075 20 7788 SCOTT ANALYST 7566 19-APR-87 3100 20 7902 FORD ANALYST 7566 03-DEC-81 3100 20 7369 SMITH FDA 7902 17-DEC-80 900 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30 7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30 7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30 7876 ADAMS FDA 7788 23-MAY-87 1200 20 7900 JAMES FDA 7698 03-DEC-81 1050 30 7934 MILLER FDA 7782 23-JAN-82 1400 10 14 rows selected. 62.)write an update statement to update al the manager sal to Rs.100 who are working in New York ? SQL> update emp set sal=sal+100 where job='MANAGER' and deptno in (select deptno from dept where loc='NEW YORK'); 1 row updated. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7839 KING PRESIDENT 17-NOV-81 5100 10 7698 BLAKE MANAGER 7839 01-MAY-81 2950 30 7782 CLARK MANAGER 7839 09-JUN-81 2650 10 7566 JONES MANAGER 7839 02-APR-81 3075 20 7788 SCOTT ANALYST 7566 19-APR-87 3100 20 7902 FORD ANALYST 7566 03-DEC-81 3100 20 7369 SMITH FDA 7902 17-DEC-80 900 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30 7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30 7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30 7876 ADAMS FDA 7788 23-MAY-87 1200 20 7900 JAMES FDA 7698 03-DEC-81 1050 30 7934 MILLER FDA 7782 23-JAN-82 1400 10 14 rows selected. SQL> select * from dept;
  • 21. DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 63.)write a delete statement to delete all the employee records who are working as manager ? SQL> delete from emp where job='MANAGER'; 3 rows deleted. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7839 KING PRESIDENT 17-NOV-81 5100 10 7788 SCOTT ANALYST 7566 19-APR-87 3100 20 7902 FORD ANALYST 7566 03-DEC-81 3100 20 7369 SMITH FDA 7902 17-DEC-80 900 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30 7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30 7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30 7876 ADAMS FDA 7788 23-MAY-87 1200 20 7900 JAMES FDA 7698 03-DEC-81 1050 30 7934 MILLER FDA 7782 23-JAN-82 1400 10 11 rows selected. 64.)write a delete statement to delete all the employee records who are working with New York ? SQL> delete from emp where deptno in (select deptno from dept where loc='NEW YORK'); 2 rows deleted. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7788 SCOTT ANALYST 7566 19-APR-87 3100 20 7902 FORD ANALYST 7566 03-DEC-81 3100 20 7369 SMITH FDA 7902 17-DEC-80 900 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30 7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30 7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30 7876 ADAMS FDA 7788 23-MAY-87 1200 20 7900 JAMES FDA 7698 03-DEC-81 1050 30 9 rows selected. 65.)write a delete statement to delete all the employee who are working in SCOTTs dept. as managers and getting a salary greater than the average salary of a clerk ?
  • 22. SQL> delete from emp where deptno in (select deptno from emp where ename='SCOTT' and job='MANAGER') and sal > (select avg(sal) from emp where job='CLERK'); 0 rows deleted.