Relational Algebra
Relational Algebra
0
• Thus is defined to be a cross-product followed by a
0
selection.
• Note that the condition c can (and typically does) refer to
attributes of both R and S.
Equijoin
•When join uses only equality comparison operator,
it is said to be equijoin.
•when the join condition consists solely of equalities
(connected by ^) of the form R.name1 = S.name2, that
is, equalities between two fields in R and S.
•For join conditions that contain only such equalities,
the join operation is refined by doing an additional
projection.
•The join operation with this refinement is called
equijoin.
Sql Query for EquiJoin
SELECT column_list
FROM table1, table2....
WHERE table1.column_name =
table2.column_name;
or
SELECT *
FROM table1
JOIN table2
[ON (join_condition)]
Natural Join
• a natural join, and it has the nice property that the result is
guaranteed not to have two fields with the same name.
• The equijoin expression S1 ⊲⊳R.sid=S.sid R1 is actually a natural join
and can simply be denoted as S1 ⊲⊳ R1, since the only common field
is sid.
• If the two relations have no attributes in common, S1 ⊲⊳ R1 is simply
the cross-product.
• Select * from table1 naturaljoin table2
• Division
• The division operator is useful for expressing certain kinds of queries,
for example:
• “Find the names of sailors who have reserved all boats.”
• the division operator does not have the same importance as the other
operators—it is not needed as often, and database systems do not try
to exploit the semantics of division by implementing it as a distinct
operator
• We can compute disqualified tuples using the algebra expression
• πx((πx(A) × B) − A)
• Thus we can define A/B as
• πx(A) − πx((πx(A) × B) − A