Lab-8-Implementation of different types of Joins
Lab-8-Implementation of different types of Joins
Database Systems
Laboratory Manual
0702325
▪ Theory :
The SQL Joins clause is used to combine records from two or more tables in a
database. A JOIN is a means for combining fields from two tables by using values
common to each .The join is performed by the ‘where’ clause which combines
specified rows of tables.
Syntax:
SELECT column 1, column 2, column 3...
FROM table_name1, table_name2
WHERE table_name1.column name = table_name2.columnname;
▪ Types of Joins :
1. Simple Join
2. Self Join
3. Outer Join
Table aliases are used to make multiple table queries shorted and more
readable. We give an alias name to the table in the ‘from’ clause and use it
instead of the name throughout the query.
➢ Self join: Joining of a table to itself is known as self-join. It joins one row in a
table to another. It can compare each row of the table to itself and also with
other rows of the same table.
Example: select * from emp x ,emp y
where x.salary >= (select avg(salary) from x.emp where x. deptno =y.deptno);
Example:
SELECT E.EmpName, D.DeptName
FROM Employees E
LEFT OUTER JOIN Departments D
ON E.DeptID = D.DeptID;
Example:
SELECT E.EmpName, D.DeptName
FROM Employees E
RIGHT OUTER JOIN Departments D
ON E.DeptID = D.DeptID;
1. Find all information of sailors who have reserved boat number 101.
2. Find the name of boat reserved by Bob.
3. Find the names of sailors who have reserved a red boat, and list in the order of
age.
4. Find the names of sailors who have reserved at least one boat.
5. Find the ids and names of sailors who have reserved two different boats on the
same
day.
Post lab :
1. Find the ids of sailors who have reserved a red boat or a green boat.
2. Find the name and the age of the youngest sailor.
3. Count the number of different sailor names.
4. Find the average age of sailors for each rating level.
5. Find the average age of sailors for each rating level that has at least two
sailors.