Implementation of Different Types of Joins
Implementation of Different Types of Joins
In the above statement, R.bid = 101 performs the equalities statement. It retrieves rows from both
the tables provided they both have the same id as specified by the where clause. Since the where
clause uses the comparison operator (=) to perform a join, it is said to be equijoin. It combines the
matched rows of tables. It can be used as follows:
Non Equi-join:
It specifies the relationship between columns belonging to different tables by making use of
relational operators other than’=’.
Example:
Find all information of sailors who have not reserved boat number 103.
SELECT S.*
FROM Sailors S, Reserves R
WHERE S.sid = R.sid AND R.bid < > 103
Table Aliases
Table aliases are used to make multiple table queries shorted and more readable. We givean 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 sailors X, sailors Y
WHERE X.age >= (
);
SELECT AVG ( age) FROM X.sailors;
Outer Join:
▪ It extends the result of a simple join. An outer join returns all the rows returned by
simplejoin as well as those rows from one table that do not match any row from the
table.
▪ The symbol(+) represents outer join.
Outer Join
• Inner Join
• Left Join
• Right Join
• Full Outer Join
• SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.
• INNER JOIN
The INNER JOIN keyword selects records that have matching values in both tables.
• JOIN or INNER JOIN
JOIN and INNER JOIN will return the same result.
INNER is the default join type for JOIN, so when you write JOIN the parser actually
writes INNER JOIN.
Left side Contents-Output side:
PRACTICE ASSIGNMENT:
Consider the following schema:
➢ Sailors (sid, sname, rating, age)
sid bid
sname banme
rating color
age
Reserves Entity
sid
bid
day(date)
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 22, 'Dustin', 7, 45.0);
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 29, 'Brutus', 1, 33 );
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 31, 'Lubber', 8,
55.5);
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 32, 'Andy', 8, 25.5 );
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 58, 'Rusty', 10, 35 );
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 64, 'Horatio', 7, 35 );
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 71, 'Zorba', 10, 16 );
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 74, 'Horatio', 9, 40 );
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 85, 'Art', 3, 25.5 );
INSERT INTO sailors( sid, sname, rating, age )VALUES ( 95, 'Bob', 3, 63.5 );
INSERT INTO boats ( bid, bname, color ) VALUES ( 102, 'Interlake', 'red' );
INSERT INTO boats ( bid, bname, color ) VALUES ( 103, 'Clipper', 'green' );
INSERT INTO boats ( bid, bname, color ) VALUES ( 104, 'Marine', 'red' );
Output:
bname
Clipper
Marine
Result:
Thus the Implementation of different types of Joins was completed successfully