Database Systems - Lecture 8
Database Systems - Lecture 8
EXAMPLE 1
ρ (A, B) (Department)
EXAMPLE 2
Query to rename the table name Project to Pro and its attributes to P, Q, R.
ρ Pro(P, Q, R) (Project)
EXAMPLE 3
Query to rename the first attribute of the table Student with attributes A, B, C to P.
ρ (P, B, C) (Student)
JOIN OPERATIONS
Join is a combination of a Cartesian product followed by a selection process.
A Join operation pairs two tuples from different relations, if and only if a given join condition
is satisfied. Join operation denoted by ⋈.
JOIN operation also allows joining variously related tuples from different relations.
TYPES OF JOINS
INNER JOINS
• THETA JOIN
• EQUI JOIN
• NATURAL JOIN
OUTER JOIN
• LEFT OUTER JOIN
• RIGHT OUTER JOIN
• FULL OUTER JOIN
1
INNER JOINS
In an inner join, only those tuples that satisfy the matching criteria are included, while the rest
are excluded. Inner join includes:
THETA JOIN
This is the general case of JOIN operation. It is denoted by symbol θ.
EXAMPLE
R1 ⋈θR2
Theta join can use any conditions in the selection criteria. R1 and R2 are relations having
attributes (A1, A2, .., An) and (B1, B2,.. ,Bn) such that the attributes don’t have anything in
common, that is R1 ∩ R2 = Φ.
Theta join can use all kinds of comparison operators.
2
Solution
EQUI JOIN.
This is a join based on equality or matching column values. It is a theta join that uses only the
equality comparison operator.
It is the most difficult operation to implement efficiently using SQL in an RDBMS and one
reason why RDBMS have essential performance problems.
3
OUTER JOIN
In an outer join, along with tuples that satisfy the matching criteria, we also include some or
all tuples that do not match the criteria.
The left outer join operation allows keeping all tuples in the left relation.
However, if there is no matching tuple is found in right relation, then the attributes of right
relation in the join result are filled with null values.
4
RIGHT OUTER JOIN: (A B)
The right outer join operation allows keeping all tuple in the right relation.
However, if there is no matching tuple is found in the left relation, then the attributes of the
left relation in the join result are filled with null values.
5
6