Lab Report 5 Final
Lab Report 5 Final
Santosh, Tangail-1902
Lab Report 05
Course Title: Database Management System Lab
Course Code: ICT-2108
Lab Report on: Different Types of Joining Operations in MySQL
Submitted By Submitted To
Experiment No: 05
Experiment Name: Different Types of Joining Operations in MySQL
Objectives: We will learn how to join two tables using different types of joining. We
will also learn how to use joining operations with specific and required conditions to
find desired output.
Required Instruments:
1. MySQL 8.3 Command line Client.
For the purpose of joining, a classroom table is created and data has been inserted in
that table.
Inner join:
SQL expression: select dept_name,
budget, room_number,
capacity from department inner
join classroom;
Here, this query selects the department name, budget, room number, and classroom
capacity by joining the department and classroom tables based on the shared
“room_number” field.
SQL expression: select name, course_id, salary, year from instructor inner join teaches on
instructor.ID = teaches.ID;
This query selects the instructor's name, course ID, salary, and the year they taught the
course, joining the instructor and teaches tables using the common ID field.
Left join:
SQL expression: select instructor.ID, instructor.name, department.building from
instructor left join department on instructor.dept_name= department.dept_name;
This query performs a left join between the instructor and department tables based on
the “dept_name” field. The left join ensures that all records from the instructor table
are included, even if there’s no corresponding entry in the department table.
Right join:
departmen
t
The Right Join ensures that all rows from the instructor table are returned, even if
there is no matching dept_name in the department table. If no match is found, the
building and budget from the department table will be NULL
The RIGHT JOIN ensures that all rows from the department table are returned, even if
there is no matching building in the classroom table. If no match is found in the
classroom table, the room_number and capacity will return NULL.
Full join:
SQL expression: select *from classroom left join department on classroom.building =
department.building union : select *from classroom right join department on
classroom.building = department.building;
The above query is a full join that combines the results of two different joins—LEFT
JOIN and RIGHT JOIN—using the UNION operator. This allows you to retrieve all
unique rows from both joins meaning it will have all the data from both classroom and
department.
The above query is a full join that combines the results of two different joins—LEFT
JOIN and RIGHT JOIN—using the UNION operator. This allows you to retrieve all
unique rows from both joins meaning it will have all the data from both course and
department.
SQL expression: select name, ID, dept_name, semester, year from instructor natural join
teaches;
This SQL query is a natural join which will combine the department and classroom
tables based on the common columns that has the same in both instructor and teaches.
SQL expression: select course_id, title, room_number, time_slot_id from course natural
join section;
This SQL query is a natural join which will combine the department and classroom
tables based on the common columns that has the same in both course and section.
Discussion:
By the above query we can use various types of joining like inner join, left join, right join,
natural join, full join to find desired set of data from databases.