The 6 Fundamental Relational Algebra Operators
The 6 Fundamental Relational Algebra Operators
1. Selection (σ)
Filters horizontal rows (tuples) satisfying a given condition.
2. Projection (π)
Filters vertical columns (attributes) and removes duplicates.
3. Cartesian Product (×)
Combines every row of table A with every row of table B.
4. Union (∪)
Combines all rows from two union-compatible tables.
5. Set Difference (−)
Finds rows present in table A but NOT present in table B.
6. Rename (ρ)
Renames the relation or its attribute names.
Explanation
- Selection filters rows and projection selects attributes.
- Union, difference, product and rename provide other basic ways to build an expression.
The Join Spectrum
The Join Spectrum
1. Theta Join (θ-Join)
Cross product followed by a condition using any comparison operator (<, >, =, !=).
2. Equi-Join
A Theta join where the condition strictly uses the equality operator (=).
3. Natural Join (⋈)
Equi-join on all common attributes, automatically eliminating duplicate columns!
Explanation
- A theta join uses a comparison condition and an equijoin uses equality.
- A natural join matches common attribute names and presents one copy of each matching column.
The Three Outer Joins
The Three Outer Joins
Left Outer Join (⟕)
Preserves ALL rows from Left Table
Preserves ALL rows from Left Table
Right Outer Join (⟖)
Preserves ALL rows from Right Table
Preserves ALL rows from Right Table
Full Outer Join (⟗)
Preserves ALL rows from BOTH Tables
Preserves ALL rows from BOTH Tables
Explanation
- A left outer join keeps unmatched left rows and a right outer join keeps unmatched right rows.
- A full outer join preserves unmatched rows from both inputs.
Finding borrowers by name
Finding borrowers by name
Borrowing records
Read the borrower identifier
Join with students
Match each identifier to its student record
Project names
Return the requested attribute
Explanation
- Join a borrowing record to its student using the shared identifier.
- Project the name only after that match has been made.
General Anatomy of a TRC Expression
General Anatomy of a TRC Expression
{ t | P(t) }
➔ t: Tuple Variable (Target List)
➔ \|: Such that ("where")
➔ P(t): Qualifying Predicate Formula
Explanation
- A tuple variable represents a complete row.
- The condition determines which rows supply values to the answer.
Structure of a DRC Expression
Structure of a DRC Expression
< x1, x2, ..., xn >
Domain Variables (Target Columns)
Domain Variables (Target Columns)
➔ \| (Such that) ➔
P(x1, x2, ..., xn)
Qualifying Predicate Formula
Qualifying Predicate Formula
Explanation
- Domain variables stand for individual values rather than whole rows.
- The predicate specifies which combinations of values belong in the result.