S.NO. TOPIC DATE SIGN.
REMARK
1. Retrieve the complete data from employee
table.
2. List all the distinct department no. from
employee table.
3. Retrieve the list of names and jobs of all the
employee.
4. Give the name and job of all the employees
from DEPT_NO 10.
5. Display the information for EMP_NO 7369
AND 7499.
6. Display the employees name with their
annual salary.
7. Display all the data in ascending order of
salary.
8. Display all the data in the descending order
of salary.
9. Display all the data in the descending order
of DEPT_NO and ascending order of SALARY
10. Select distinct Dept_no and Job from
employee table in increasing order of
Dept_No.
11. Display all the information of mangers from
DEPT_NO. 10.
12. Display all those employees who are either
manager or getting more than salary 5000.
13. Retrieve all the employees who are other
than manager and sales person
14. Retrieve all the employees who are getting
salary in between 2000 and 5000
15. Retrieve all the employees who are either
in Dept-No. 10 or 20.
16. Retrieve all the employees whose name
starts from character ‘ A’.
17. Retrieve all the employees whose name
ends with character ‘ S’.
18. Retrieve all the employees whose name
includes character ‘R’ in their names.
19. Displays details of all employees where
length of name is just four characters and
first two letter are ‘K’ and ‘I’.
20. Display maximum salary,minimum
salary,average salary and sum of salary
from employee table.
21. Change the name of SMITH by JOHN in
employee table.
22. Change the salary of BLAKE by Rs.4000.
23. Delete the record of smith from employee
table
24. Add a new column phone_no in the
employee table.
25. Change the size of emp_name field in
employee table.
26. Drop the commission column from the table
along with data.
27. Drop the TABLE EMPLOYEE.
28. Rename the EMP table to EMP1.
29. Find out the maximum salary of each
department.
30. Find out the maximum salary for all the
departments having more than three
employees.
31. List all the employees from sales
department.
32. Update the salary of smith the highest
salary of the company.
33. Get the name of the employees who are
getting second highest salary.
34. Retrieve the name of all the employees
who work in smith’s department.
35. Create an index empno_id on the
employee,field emp_no.
36. Create an index on the department,field
dept_no.
QUERY-NO.1
QUERY- Retrieve the complete data from employee
table.
SQL command for the query:-
Select * from EMP;
Result for the query:-
EMP_NO EMP_NAME JOB MGR HIREDATE SALARY COMM DEPT_NO
7369 SMITH CLERK 7902 17-DEC-80 800 - 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 - 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 - 30
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20
7839 KING PRESIDENT - 11-NOV-81 5000 - 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 - 30
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20
7900 JAMES CLERK 7698 03-DEC-81 950 - 30
7902 FORD ANALYST 7566 03-DEC-81 3000 - 20
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10
QUERY-NO.2
QUERY:-List all the distinct department no. from
employee table.
SQL command for the query:
Select DEPT_NO from EMP;
Result for the query:-
DEPT _NO
20
20
30
30
30
30
10
20
20
30
20
30
20
10
QUERY-NO.3
QUERY:- Retrieve the list of names and jobs of all the
employee.
SQL command for the query:-
select EMP_NAME,JOB from EMP;
Result for the query-
EMP_N AME JOB
SMITH CLERK
JONES MANAGER
MARTIN SALEMAN
ALLEN SALEMAN
WARD SALEMAN
BLAKE MANAGER
CLARKS MANAGER
SCOTT ANALYST
KING PRESIDENT
TURNER SALEMAN
ADAMS CLERK
JAMES CLERK
FORD ANALYST
MILLER CLERK
QUERY-NO.4
QUERY:--Give the name and job of all the employees
from DEPT_NO 10.
SQL command for the query:-
select EMP_NAME,JOB from EMP where DEPT_NO=10;
Result for the query-
EMP_N AME JOB
CLARKS MANAGER
KING PRESIDENT
MILLER CLERK
QUERY-NO.5
QUERY:-Display the information for EMP_NO 7369 AND
7499.
SQL command for the query:-
select * from EMP where(EMP_NO=7369 and
EMP_NO=7499);
Result for the query:-
EMP_NO EMP_N AME JOB MGR HIREDATE SAL ARY COMM DEPT _NO
7369 SMITH CLERK 7902 17-DEC-80 800 - 20
7499 ALLEN SALEMAN 7698 20-FEB-81 1600 300 30
QUERY-NO.6
QUERY:-Display the employees name with their annual
salary.
SQL command for the query:-
Select SALARY,EMP_NAME from EMP;
Result for the query:-
SAL ARY EMP_N AME
800 SMITH
2975 JONES
1250 MARTIN
1600 ALLEN
1250 WARD
2850 BLAKE
2450 CLARKS
3000 SCOTT
5000 KING
1500 TURNER
1100 ADAMS
950 JAMES
3000 FORD
1300 MILLER
QUERY-NO.7
QUERY:-Display all the data in ascending order of
salary.
SQL command for the query:-
select * from EMP order by SALARY asc;
Result for the query-
EMP_NO EMP_N AME JOB MGR HIREDATE SAL ARY COMM DEPT _NO
7369 SMITH CLERK 7902 17-DEC-80 800 - 20
7900 JAMES CLERK 7698 03-DEC-81 950 - 30
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20
7654 MARTIN SALEMAN 7698 28-SEP-81 1250 400 30
7521 WARD SALEMAN 7698 22-FEB-81 1250 500 30
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10
7844 TURNER SALEMAN 7698 08-SEP-81 1500 - 30
7499 ALLEN SALEMAN 7698 20-FEB-81 1600 300 30
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 - 30
7566 JONES MANAGER 7839 02-APR-81 2975 - 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20
7900 FORD ANALYST 7566 03-DEC-81 3000 - 20
7839 KING PRESIDENT 0 17-NOV-81 5000 - 20
QUERY-NO.8
QUERY:-Display all the data in the descending order of
salary.
SQL command for the query:-
select * from EMP order by SALARY desc;
Result for the query-
EMP_NO EMP_N AME JOB MGR HIREDATE SAL ARY COMM DEPT _NO
7839 KING PRESIDENT 0 17-NOV-81 5000 - 20
7900 FORD ANALYST 7566 03-DEC-81 3000 - 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20
7566 JONES MANAGER 7839 02-APR-81 2975 - 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 - 30
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10
7499 ALLEN SALEMAN 7698 20-FEB-81 1600 300 30
7844 TURNER SALEMAN 7698 08-SEP-81 1500 - 30
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10
7654 MARTIN SALEMAN 7698 28-SEP-81 1250 400 30
7521 WARD SALEMAN 7698 22-FEB-81 1250 500 30
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20
7900 JAMES CLERK 7698 03-DEC-81 950 - 30
7369 SMITH CLERK 7902 17-DEC-80 800 - 20
QUERY-NO.9
QUERY- Display all the data in the descending order of
DEPT_NO and ascending order of SALARY.
SQL command for the query:
select * from EMP order by DEPT_NO desc,SALARY asc;
Result for the query-
EMP_NO EMP_N AME JOB MGR HIREDATE SAL ARY COMM DEPT _NO
7900 JAMES CLERK 7698 03-DEC-81 950 - 30
7654 MARTIN SALEMAN 7698 28-SEP-81 1250 400 30
7521 WARD SALEMAN 7698 22-FEB-81 1250 500 30
7844 TURNER SALEMAN 7698 08-SEP-81 1500 - 30
7499 ALLEN SALEMAN 7698 20-FEB-81 1600 300 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 - 30
7369 SMITH CLERK 7902 17-DEC-80 800 - 20
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20
7566 JONES MANAGER 7839 02-APR-81 2975 - 20
7900 FORD ANALYST 7566 03-DEC-81 3000 - 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10
7839 KING PRESIDENT 0 17-NOV-81 5000 - 10
QUERY _NO.10
QUERY-Select distinct Dept_no and Job from employee
table in increasing order of Dept_No.
SQL command for the query-
select DEPT_NO,JOB from EMP order by DEPT_NO asc;
Result for the query-
QUERY _NO.11
QUERY- Display all the information of mangers from
DEPT_NO. 10.
SQL command for the query-
select * from EMP where DEPT_NO=10 and
JOB='MANAGER';
Result for the query-
QUERY _NO.12
QUERY- Display all those employees who are either
manager or getting more than salary 5000.
SQL command for the query-
select * from EMP where JOB='MANAGER' or
SALARY>5000;
Result for the query-
QUERY _NO.13
QUERY- Retrieve all the employees who are other than
manager and sales person.
SQL command for the query-
Select EMP_NAME from EMP where JOB!=’MANAGER’
and JOB!=’SALESMAN’;
Result for the query-
QUERY _NO.14
QUERY- Retrieve all the employees who are getting
salary in between 2000 and 5000.
SQL command for the query-
select * from EMP where SALARY between 2000 and
5000;
Result for the query-
QUERY _NO.15
QUERY- Retrieve all the employees who are either in
Dept-No. 10 or 20.
SQL command for the query-
select EMP_NAME from EMP where DEPT_NO=10 or
DEPT_NO=20;
Result for the query-
QUERY _NO.16
QUERY- Retrieve all the employees whose name starts
from character ‘ A’.
SQL command for the query-
select * from EMP where EMP_NAME like 'A%';
Result for the query-
QUERY _NO.17
QUERY-Retrieve all the employees whose name ends
with character ‘ S’.
SQL command for the query-
select * from EMP where EMP_NAME like '%S';
Result for the query-
QUERY _NO.18
QUERY- Retrieve all the employees whose name
includes character ‘R’ in their names.
SQL command for the query-
select * from EMP where EMP_NAME like '%R%';
Result for the query-
QUERY _NO.19
QUERY-Displays details of all employees where length of
name is just four characters and first two letter are ‘K’
and ‘I’.
SQL command for the query-
select * from EMP where EMP_NAME like 'KI ';
Result for the query-
QUERY _NO.20
QUERY-Display maximum salary,minimum
salary,average salary and sum of salary from employee
table.
SQL command for the query-
Select
max(SALARY),min(SALARY),avg(SALARY),sum(SALARY)
from EMP;
Result for the query-
QUERY _NO.21
QUERY- Change the name of SMITH by JOHN in
employee table.
SQL command for the query-
Update EMP set EMP_NAME=’JOHN’ where
EMP_NAME=’SMITH’;
Result for the query-
EMP_NO EMP_NAME JOB MGR HIREDATE SALARY COMM DEPT_NO
7369 JOHN CLERK 7902 17-DEC-80 800 - 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 - 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 - 30
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20
7839 KING PRESIDENT - 11-NOV-81 5000 - 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 - 30
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20
7900 JAMES CLERK 7698 03-DEC-81 950 - 30
7902 FORD ANALYST 7566 03-DEC-81 3000 - 20
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10
QUERY _NO.22
QUERY- Change the salary of BLAKE by Rs.4000.
SQL command for the query-
Update EMP set SALARY=4000 where
EMP_NAME=’BLAKE’;
Result for the query-
EMP_NO EMP_NAME JOB MGR HIREDATE SALARY COMM DEPT_NO
7369 JOHN CLERK 7902 17-DEC-80 800 - 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 - 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 4000 - 30
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20
7839 KING PRESIDENT - 11-NOV-81 5000 - 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 - 30
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20
7900 JAMES CLERK 7698 03-DEC-81 950 - 30
7902 FORD ANALYST 7566 03-DEC-81 3000 - 20
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10
QUERY _NO.23
QUERY- Delete the record of smith from employee table.
SQL command for the query-
Delete from EMP where EMP_NAME=’SMITH’;
Result for the query-
EMP_NO EMP_NAME JOB MGR HIREDATE SALARY COMM DEPT_NO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 - 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 4000 - 30
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20
7839 KING PRESIDENT - 11-NOV-81 5000 - 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 - 30
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20
7900 JAMES CLERK 7698 03-DEC-81 950 - 30
7902 FORD ANALYST 7566 03-DEC-81 3000 - 20
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10
QUERY _NO.24
QUERY- Add a new column phone_no in the employee
table.
SQL command for the query-
Alter table EMP add(PHONE_NO number(10));
Result for the query-
EMP_NO EMP_NAME JOB MGR HIREDATE SALARY COMM DEPT_NO PHONE_NO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 -
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 -
7566 JONES MANAGER 7839 02-APR-81 2975 - 20 -
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 -
7698 BLAKE MANAGER 7839 01-MAY-81 4000 - 30 -
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10 -
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20 -
7839 KING PRESIDENT - 11-NOV-81 5000 - 10 -
7844 TURNER SALESMAN 7698 08-SEP-81 1500 - 30 -
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20 -
7900 JAMES CLERK 7698 03-DEC-81 950 - 30 -
7902 FORD ANALYST 7566 03-DEC-81 3000 - 20 -
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10 -
QUERY NO.25
QUERY- Change the size of emp_name field in employee
table.
SQL command for the query-
Alter table EMP modify (EMP_NAME varchar(20));
Result for the query-
EMP_NO EMP_NAME JOB MGR HIREDATE SALARY COMM DEPT_NO PHONE_NO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 -
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 -
7566 JONES MANAGER 7839 02-APR-81 2975 - 20 -
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 -
7698 BLAKE MANAGER 7839 01-MAY-81 4000 - 30 -
7782 CLARKS MANAGER 7839 09-JUN-81 2450 - 10 -
7788 SCOTT ANALYST 7566 19-APR-87 3000 - 20 -
7839 KING PRESIDENT - 11-NOV-81 5000 - 10 -
7844 TURNER SALESMAN 7698 08-SEP-81 1500 - 30 -
7876 ADAMS CLERK 7788 23-MAY-81 1100 - 20 -
7900 JAMES CLERK 7698 03-DEC-81 950 - 30 -
7902 FORD ANALYST 7566 03-DEC-81 3000 - 20 -
7934 MILLER CLERK 7782 23-JAN-82 1300 - 10 -
QUERY NO.26
QUERY- Drop the commission column from the table
along with data.
SQL command for the query-
Alter table EMP drop column COMM;
Result for the query-
EMP_NO EMP_NAME JOB MGR HIREDATE SALARY DEPT_NO PHONE_NO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 30 -
7521 WARD SALESMAN 7698 22-FEB-81 1250 30 -
7566 JONES MANAGER 7839 02-APR-81 2975 20 -
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 30 -
7698 BLAKE MANAGER 7839 01-MAY-81 4000 30 -
7782 CLARKS MANAGER 7839 09-JUN-81 2450 10 -
7788 SCOTT ANALYST 7566 19-APR-87 3000 20 -
7839 KING PRESIDENT - 11-NOV-81 5000 10 -
7844 TURNER SALESMAN 7698 08-SEP-81 1500 30 -
7876 ADAMS CLERK 7788 23-MAY-81 1100 20 -
7900 JAMES CLERK 7698 03-DEC-81 950 30 -
7902 FORD ANALYST 7566 03-DEC-81 3000 20 -
7934 MILLER CLERK 7782 23-JAN-82 1300 10 -
QUERY NO.27
QUERY- Drop the TABLE EMPLOYEE.
SQL command for the query-
Drop table EMP;
Result for the query-
Table dropped.
QUERY NO.28
QUERY- Rename the EMP table to EMP1.
SQL command for the query-
Rename EMP to EMP1;
Result for the query-
Statement processed.
QUERY NO.29
QUERY- Find out the maximum salary of each
department.
SQL command for the query-
Select DEPT_NO,max(SALARY) from EMP group by
DEPT_NO;
R esult for the query-
QUERY NO.30
QUERY- Find out the maximum salary for all the
departments having more than three employees.
SQL command for the query-
Select max(SALARY) from EMP group by DEPT_NO
having count(*)>3;
R esult for the query:
M AX(SALARY)
4000
3000
QUERY NO.31
QUERY- List all the employees from sales department;
SQL command for the query-
Select EMP_NAME from where DEPT_NO=(select
DEPT_NO from DEPT where DEPT_NAME=’SALES’);
R esult for the query:
QUERY NO.32
QUERY- update the salary of smith the highest salary of
the company.
SQL command for the query-
Update EMP set SALARY=(select max(SALARY) from EMP)
where EMP_NAME=’SMITH’;
R esult for the query: -
1 row(s) updated.
QUERY NO.33
QUERY- Get the name of the employees who are getting
second highest salary;
SQL command for the query-
Select max(SALARY) from EMP where SALARY=(select
max(SALARY) from EMP where SALARY<(select
max(SALARY) from EMP));
R esult for the query: -
QUERY NO.34
QUERY:- Retrieve the name of all the employees who
work in smith’s department.
SQL command for the query-
Select EMP_NAME from emp where DEPT_NO=(select
DEPT_NO from EMP where EMP_NAME=’SMITH’;
R esult for the query: -
QUERY NO.35
QUERY:- Create an index empno_id on the
employee,field emp_no;
SQL command for the query-
Create index EMPNO_ID on EMP(EMP_NO);
R esult for the query: -
Index created;
QUERY NO.36
QUERY:- Create an index on the department,field
dept_no.
SQL command for the query-
Create index DEPTNO_ID on DEPT(DEPT_NO);
R esult for the query: -
Index created;