0% found this document useful (0 votes)
13 views8 pages

A24 Exp03 DBMS

The document outlines an experiment on using JOIN operations in Oracle 9i, focusing on retrieving data from multiple tables through various types of joins including equijoins, non-equijoins, outer joins, cross joins, and natural joins. It provides syntax examples for each join type and includes a lab assignment with specific queries to practice these concepts. The document concludes with a code section demonstrating table creation and data insertion for the EMPLOYEES and DEPARTMENTS tables.

Uploaded by

vikas.231203101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

A24 Exp03 DBMS

The document outlines an experiment on using JOIN operations in Oracle 9i, focusing on retrieving data from multiple tables through various types of joins including equijoins, non-equijoins, outer joins, cross joins, and natural joins. It provides syntax examples for each join type and includes a lab assignment with specific queries to practice these concepts. The document concludes with a code section demonstrating table creation and data insertion for the EMPLOYEES and DEPARTMENTS tables.

Uploaded by

vikas.231203101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1

Mumbai University
Vidyavardhini’s College of Engineering and Technology, Vasai

Experiment No: - 3

Experiment Name: - Practical using JOIN operations

Aim: - Performing practical by using multiple tables

Resource required: - Oracle 9i - iSQLplus

Theory: -

• DISPLAYING DATA FROM MULTIPLE TABLES:


Cartesian Products: It is formed when:
- a join condition is omitted
- a join condition is invalid
- All rows in the first table are joined to all rows in the second table.

Syntax: Joining tables


SELECT table1.column, table2.column
FROM table1, table2
WHERE table1.column1= table2.column2;
- write the join condition in the WHERE clause.

1. Retrieving record with Equijoin/simple join/ inner join:


e.g.: SELECT employees.employee_id, employees.last_name,
employees.department_id, departments.department_id,
departments.location_id
FROM employees, departments
WHERE employees.department_id = departments.department_id;

2. Retrieving record with Non-Equijoins: contain something other than equality operator. e.g.:
SELECT e.last_name, e.salary, j.grade_level
FROM employees e, job_grades j
WHERE e.salary
BETWEEN j.lowest_sal AND j.highest_sal;

3. Outer join: the missing rows can be returned if an outer join operator is used in join condition.

>> LEFT OUTER JOIN


e.g.: SELECT e.last_name, e.department-id, and d.department_name
FROM employees e
LEFT OUTER JOIN departments d ON (e.
department_id = d.department_id); - ON
clause used to join specify column.
>> RIGHT OUTER JOIN
e.g.: SELCET e.last_name, e.department_id, d.department_name
FROM employees e

RIGHT OUTER JOIN departments d


ON (e.department_id = d.department_id);
>> FULL OUTER JOIN
e.g.: SELECT e.last_name, e.department-id, and d.department_name
FROM employees e
FULL OUTER JOIN departments d
ON (e. department_id = d.department_id);

4. Cross joins: produces the cross product of two tables.


e.g.: SELECT last_name, department_name
FROM employees
CROSS JOIN departments;

5. Natural Joins: select record from tables that have equal values in all matched columns. e .g.:
SELECT department_id, department_name’ location-id, city
FROM departments
NATURAL JOIN locations;

Conclusion:
You should have learned how to use joins to display data from multiple tables

Lab Assignment No- 03

1. Write a query to display the last_name and department_name of all the employees 2. Write a

query to perform a CROSS JOIN of the tables EMPLOYEES and DEPARTMENTS

3. Write a query to display the last name, department name, location_ID, and city of all employees
who earn a commission
4. Create a unique listing of all job_id’s that are in department 80. Include the City of the
department in the output.

5. Write a query to perfom a LEFT OUTER Join on the tables EMPLOYEES and
DEPARTMENTS

6. Write a query to perform a RIGHT OUTER Join on the tables EMPLOYEES and
DEPARTMENTS

7. Write a query to perform a FULL OUTER Join on the tables EMPLOYEES and
DEPARTMENTS

Code:
CREATE TABLE employ(
employee_id INTEGER,
last_name VARCHAR2(50),
job_id VARCHAR2(50),
department_id integer,
salary INTEGER,
commision INTEGER,
department_name varchar2(50),
location_id varchar2(50),
city varchar2(50)
);

INSERT INTO employ VALUES(100, 'King','SA_REP', 80, 10000,2000,'COMPS','E1','mumbai');


INSERT INTO employ VALUES(101, 'Kochhar', 'ST_CLERK', 67,20000,3000,'IT','E2','delhi');
INSERT INTO employ VALUES(102, 'De Haan', 'AD_VP', 92,30000,1500,'EXTC','E3','pune');
INSERT INTO employ VALUES(103, 'Hunold', 'IT_PROG', 45, 40000,0,'VLSI','E4','kolhapur');
INSERT INTO employ VALUES(104, 'Ernst', 'IT_PROJ', 80,50000,5000,'CSE','E5','nagpur');

SELECT employee_id AS "Employee ID",


last_name AS "Last Name",
job_id AS "Job ID",
department_id AS "Department ID",
salary AS "Salary",
commision AS "Commission",
department_name AS "Department Name",
location_id AS "Location ID",
city AS "City"
FROM employ;

SELECT last_name AS "Last Name",


department_name AS "Department Name"
From employ;

CREATE TABLE DEPARTMENTS (


department_id INTEGER PRIMARY KEY,
department_name VARCHAR(100),
location VARCHAR2(50)
);

INSERT INTO DEPARTMENTS VALUES (80, 'Human Resources', 'New York');


INSERT INTO DEPARTMENTS VALUES (62, 'Information Technology', 'San Francisco');
INSERT INTO DEPARTMENTS VALUES (77, 'Sales', 'Chicago');
INSERT INTO DEPARTMENTS VALUES (80, 'Marketing', 'Los Angeles');
INSERT INTO DEPARTMENTS VALUES (92, 'Finance', 'London');

drop table DEPARTMENTS

SELECT *
FROM employ
CROSS JOIN DEPARTMENTS;

SELECT last_name,
department_name,
location_id,
city
FROM employ
WHERE commision IS NOT NULL;

SELECT DISTINCT job_id, city


FROM employ
WHERE department_id = 80;

SELECT employ.employee_id,
employ.last_name,
employ.job_id,
employ.department_id,
employ.salary,
DEPARTMENTS.department_name,
DEPARTMENTS.location
FROM employ
LEFT OUTER JOIN DEPARTMENTS
ON employ.department_id = DEPARTMENTS.department_id;

SELECT employ.employee_id, employ.last_name, employ.job_id, employ.salary, employ.city,


DEPARTMENTS.department_name, DEPARTMENTS.location
FROM employ
RIGHT OUTER JOIN DEPARTMENTS
ON employ.department_id = DEPARTMENTS.department_id;

select * from employ;


select * from DEPARTMENTS;

SELECT employ.employee_id, employ.last_name, employ.job_id, employ.salary, employ.city,


DEPARTMENTS.department_name, DEPARTMENTS.location
FROM employ
FULL OUTER JOIN DEPARTMENTS
ON employ.department_id = DEPARTMENTS.department_id;

SELECT employ.employee_id, employ.last_name,


employ.department_id, DEPARTMENTS.department_id,
DEPARTMENTS.location
FROM employ, DEPARTMENTS
WHERE employ.department_id = DEPARTMENTS.department_id;

SELECT department_id, department_name, location


FROM DEPARTMENTS;
NATURAL JOIN location;

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy