0% found this document useful (0 votes)
10 views5 pages

Experiment No4

The document outlines an experiment involving SQL joins on two tables: employee and project. It details the creation of these tables, insertion of data, and various SQL queries to retrieve information about employees and their project assignments. The queries include inner joins, left joins, right joins, and full joins to demonstrate different ways to combine and retrieve data from the tables.

Uploaded by

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

Experiment No4

The document outlines an experiment involving SQL joins on two tables: employee and project. It details the creation of these tables, insertion of data, and various SQL queries to retrieve information about employees and their project assignments. The queries include inner joins, left joins, right joins, and full joins to demonstrate different ways to combine and retrieve data from the tables.

Uploaded by

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

EXPERIMENT NO: 4 REG.

NO: 2362159

DATE: 06-01-25

JOINS

Aim: To use joins on the given table.

Inserting Values to the table

SQL> create table employee (emp_id number(10), emp_name varchar(10), city varchar(10), salary
number(10), age number(5));

Table created.

SQL> create table project (project_no number(10), emp_id number(10), department varchar(15));

Table created.

SQL> insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age);

Enter value for emp_id: 01

Enter value for emp_name: Angelina

Enter value for city: Chicago

Enter value for salary: 200000

Enter value for age: 30

old 1: insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age)

new 1: insert into employee values (01, 'Angelina', 'Chicago', 200000, 30)

1 row created.

SQL> insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age);

Enter value for emp_id: 2

Enter value for emp_name: Robert

Enter value for city: Austin

Enter value for salary: 300000

Enter value for age: 26

old 1: insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age)

new 1: insert into employee values (2, 'Robert', 'Austin', 300000, 26)

1 row created.

SQL> insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age);

Enter value for emp_id: 3


Enter value for emp_name: Christian

Enter value for city: Denver

Enter value for salary: 100000

Enter value for age: 42

old 1: insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age)

new 1: insert into employee values (3, 'Christian', 'Denver', 100000, 42)

1 row created.

SQL> insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age);

Enter value for emp_id: 4

Enter value for emp_name: Kristen

Enter value for city: washington

Enter value for salary: 500000

Enter value for age: 29

old 1: insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age)

new 1: insert into employee values (4, 'Kristen', 'washington', 500000, 29)

1 row created.

SQL> insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age);

Enter value for emp_id: 5

Enter value for emp_name: Russell

Enter value for city: Los Angels

Enter value for salary: 200000

Enter value for age: 36

old 1: insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age)

new 1: insert into employee values (5, 'Russell', 'Los Angels', 200000, 36)

1 row created.

SQL> insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age);

Enter value for emp_id: 6

Enter value for emp_name: Marry

Enter value for city: Canada

Enter value for salary: 600000

Enter value for age: 48


old 1: insert into employee values (&emp_id, '&emp_name', '&city', &salary, &age)

new 1: insert into employee values (6, 'Marry', 'Canada', 600000, 48)

1 row created.

SQL> insert into project values (&project_no, &emp_id, '&department');

Enter value for project_no: 101

Enter value for emp_id: 1

Enter value for department: Testing

old 1: insert into project values (&project_no, &emp_id, '&department')

new 1: insert into project values (101, 1, 'Testing')

1 row created.

SQL> insert into project values (&project_no, &emp_id, '&department');

Enter value for project_no: 102

Enter value for emp_id: 2

Enter value for department: Development

old 1: insert into project values (&project_no, &emp_id, '&department')

new 1: insert into project values (102, 2, 'Development')

1 row created.

SQL> insert into project values (&project_no, &emp_id, '&department');

Enter value for project_no: 103

Enter value for emp_id: 3


Enter value for department: Designing

old 1: insert into project values (&project_no, &emp_id, '&department')

new 1: insert into project values (103, 3, 'Designing')

1 row created.

SQL> insert into project values (&project_no, &emp_id, '&department');

Enter value for project_no: 104

Enter value for emp_id: 4

Enter value for department: Development

old 1: insert into project values (&project_no, &emp_id, '&department')

new 1: insert into project values (104, 4, 'Development')


1 row created.

1. Retrieve all employees who are assigned to a project.

SQL> select employee.emp_id, employee.emp_name from employee inner join project on


employee.emp_id = project.emp_id;

EMP_ID EMP_NAME

1 Angelina
2 Robert
3 Christian
4 Kristen

2. Retrieve all employees and their assigned projects, if any. Include employees with no
project assignments.

SQL> select employee.emp_id, employee.emp_name, project.project_no from employee left


join project on employee.emp_id = project.emp_id;

EMP_ID EMP_NAME PROJECT_NO

1 Angelina 101
2 Robert 102
3 Christian 103
4 Kristen 104
6 Marry
5 Russell
6 rows selected.

3. Retrieve all projects and their assigned employees, if any. Include projects with no
assigned employees.
SQL> select project.project_no, employee.emp_id, employee.emp_name from employee
right join project on employee.emp_id = project.emp_id;
PROJECT_NO EMP_ID EMP_NAME

101 1 Angelina
102 2 Robert
103 3 Christian
104 4 Kristen

4. Retrieve all employees and all projects. Include unmatched employees and unmatched
projects.

SQL> SELECT EMPLOYEE.EMP_ID, EMPLOYEE.EMP_NAME, EMPLOYEE.CITY,


PROJECT.PROJECT_NO, PROJECT.DEPARTMENT
2 FROM EMPLOYEE
3 FULL JOIN PROJECT ON EMPLOYEE.EMP_ID = PROJECT.EMP_ID;
EMP_ID EMP_NAME CITY PROJECT_NO DEPARTMENT

1 Angelina Chicago 101 Testing


2 Robert Austin 102 Development
3 Christian Denver 103 Designing
4 Kristen washington 104 Development
6 Marry Canada
5 Russell Los Angels
6 rows selected.
5. Retrieve all employees with same employee ID using Left Outer Join.
SQL> SELECT EMPLOYEE.EMP_ID, EMPLOYEE.EMP_NAME, EMPLOYEE.CITY,
PROJECT.PROJECT_NO, PROJECT.DEPARTMENT
2 FROM EMPLOYEE
3 LEFT OUTER JOIN PROJECT ON EMPLOYEE.EMP_ID = PROJECT.EMP_ID;

EMP_ID EMP_NAME CITY PROJECT_NO DEPARTMENT

1 Angelina Chicago 101 Testing


2 Robert Austin 102 Development
3 Christian Denver 103 Designing
4 Kristen washington 104 Development
6 Marry Canada
5 Russell Los Angels

6 rows selected.

6. Retrieve all employees with same employee ID using Right Outer Join.

SQL> SELECT EMPLOYEE.EMP_ID, EMPLOYEE.EMP_NAME, EMPLOYEE.CITY, PROJECT.PROJECT_NO,


PROJECT.DEPARTMENT

2 FROM EMPLOYEE

3 RIGHT OUTER JOIN PROJECT ON EMPLOYEE.EMP_ID = PROJECT.EMP_ID;

EMP_ID EMP_NAME CITY PROJECT_NO DEPARTMENT

1 Angelina Chicago 101 Testing

2 Robert Austin 102 Development

3 Christian Denver 103 Designing

4 Kristen washington 104 Development

You might also like