You are on page 1of 6

IT248-DBMS 18IT072

PRACTICAL -2
Aim:

Theoretical Description:
In databases, data retrieval is the process of identifying and extracting data from a
database, based on a query provided by the user or application.
It enables the fetching of data from a database in order to display it on a monitor
and/or use within an application.
An SQL query can contain three types of clauses, the select clause, the from
clause, and the where clause. The role of each clause is as follows:
 The select clause is used to list the attributes desired in the result of a query.
 The from clause is a list of the relations to be accessed in the evaluation of
the query.
 The where clause is a predicate involving attributes of the relation in the
from clause.
In the case of eliminating duplicates, we insert the keyword distinct after select.
A select clause of the form select* indicates that all attributes of all relations
appearing in the form clause are selected.

Query-1: Retrieve all data from employee, jobs and deposit.


SQL Statement:
Select * from job;
Select * from employee;
Select * from deposit;

Output:

JOB_ID JOB_TITLE MIN_SAL MAX_SAL


IT_PROG Programmer 4000 10000
MK_MGR Marketing manager 9000 15000
FI_MGR Finance manager 8200 12000
FI_ACC account 4200 9000
LEC Lecturer 6000 17000
COMP_OP Computer Operator 1500 3000

CSPIT Department of Information Technology Page 1


IT248-DBMS 18IT072

A_NO CNAME BNAME AMOUNT A_DATE


103 Adama villeparle 6500 12-MAR-06
104 Aman andheri 8000 17-SEP-06
101 Smith andheri 7000 01-JAN-06
102 Snehal virar 5000 15-JUL-06
105 Anita dadar 7500 19-NOV-06
106 Sneha borivali 5500 21-DEC-06

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO


101 Smith 800 - 20
102 Snehal 1600 300 25
103 Adama 1100 0 20
104 Aman 3000 - 15
105 Anita 5000 50000 10
106 Sneha 2450 24500 10
107 Anamika 2975 - 30

Query-2: Display job title and maximum salary of all jobs.


SQL Statement:
select JOB_TITLE,MAX_SAL as maximum_salary from job;
Output:

JOB_TITLE MAXIMUM_SALARY
Programmer 10000
Marketing manager 15000
Finance manager 12000
account 9000
Lecturer 17000
Computer Operator 3000

CSPIT Department of Information Technology Page 2


IT248-DBMS 18IT072

Query-3: Display the department of employee without duplication. What is


the answer if you apply it to whole employee table?
SQL Statement:
Select distinct dept_no from employee;
select distinct* from employee;
Output:
DEPT_NO
25
30
20
15
10

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO


106 Sneha 2450 24500 10
104 Aman 3000 - 15
105 Anita 5000 50000 10
103 Adama 1100 0 20
101 Smith 800 - 20
102 Snehal 1600 300 25
107 Anamika 2975 - 30

Query-4: Give details of account no. and deposited rupees of customers


having account opened between dates 01-01-06 and 25-07-06.
SQL Statement:
select A_no, amount from deposit where a_date between '01-jan-06' and '25-jul-
06';
Output:
A_NO AMOUNT
103 6500
101 7000
102 5000

CSPIT Department of Information Technology Page 3


IT248-DBMS 18IT072

Query-5: Display all jobs with minimum salary is greater than 4000.
SQL Statement:
select * from job where min_sal>4000;
Output:
JOB_ID JOB_TITLE MIN_SAL MAX_SAL
MK_MGR Marketing manager 9000 15000
FI_MGR Finance manager 8200 12000
FI_ACC account 4200 9000
LEC Lecturer 6000 17000

Query-6: Display name and salary of employee whose department no is 20.


Give alias name to name of employee.
SQL Statement:
select emp_name as name,emp_sal from employee where dept_no=20;

Output:
NAME EMP_SAL
Smith 800
Adama 1100

Query-7: Display employee no,name and department details of those


employee whose department lies in(10,20).
SQL Statement:
select emp_name,emp_no,dept_no from employee where dept_no<20 and
dept_no>10;
Output:
EMP_NAME EMP_NO DEPT_NO
Aman 104 15

Query-8: Display employee no,name and department details of those


employee whose department not in(20,30).
SQL Statement:
select emp_name,emp_no,dept_no from employee where dept_no<20 and
dept_no>30;
Output:
no data found

CSPIT Department of Information Technology Page 4


IT248-DBMS 18IT072

Query-9: Display employee no,name and department details of those


employee whose department no is between 15 and 25.
SQL Statement:
select emp_name,emp_no,dept_no from employee where dept_no between 15 and
25;
Output:
EMP_NAME EMP_NO DEPT_NO
Smith 101 20
Snehal 102 25
Adama 103 20
Aman 104 15
Query-10: Display the non-null values of employees.
SQL Statement:
select * from employee where emp_comm is not NULL;
Output:
EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO
102 Snehal 1600 300 25
103 Adama 1100 0 20
105 Anita 5000 50000 10
106 Sneha 2450 24500 10

Query-11: Display name of customer along with its account no( both column
should be displayed as one ) whose amount is not equal to 8000 Rs.
SQL Statement:
select A_no||' '||cname from deposit where amount!=8000;
Output:
A_NO||''||CNAME
103 Adama
101 Smith
102 Snehal
105 Anita
106 Sneha

CSPIT Department of Information Technology Page 5


IT248-DBMS 18IT072

Query-12: Insert some duplicate values in deposit table and apply the concept
of Distinct and also combine two columns and display it one column using
common alias name.
SQL Statement:
select distinct A_no||' '||cname from deposit;
Output:
A_NO||''||CNAME
105 Anita
106 Sneha
102 Snehal
103 Adama
104 Aman
101 Smith

Query-13: Display the content of job details with minimum salary either 2000
or 4000.
SQL Statement:
select job_title from job where min_sal=2000 or min_sal=4000;
Output:
JOB_TITLE
Programmer

Question-1: What is query for removing same information in row retrieving?


Answer: select distinct from table_name;

Question-2: Enlist the advantages of normalizing database.


Answer: Advantages of normalizing database are:
 No duplicate entries.
 Saves storage space.
 Boasts the query performances.

Question-3: Define sub-query.


Answer: A query contained by a query is called Sub-query.

CSPIT Department of Information Technology Page 6

You might also like