Relational Algebra

Relational algebra is a procedural query language. Each operation takes relations as input and produces a relation.

OperationSymbolMeaningSQL equivalent
SelectionσFilter rowsWHERE
ProjectionπChoose columns (removes duplicates)SELECT DISTINCT cols
Union∪Rows in eitherUNION
Set difference−Rows in R but not SEXCEPT
Cartesian product×All combinationsCROSS JOIN
RenameρRename relation/attributesAS
Intersection∩Rows in bothINTERSECT
Natural join⋈Join on common attributesNATURAL JOIN
Division÷"for all" queriesNOT EXISTS … NOT EXISTS

The first six (σ, π, ∪, −, ×, ρ) are the fundamental operations; the rest can be derived from them.

Examples

Employee(eid, name, salary, dno), Dept(dno, dname)

Text
1. Names of employees earning more than 50000:
   π name ( σ salary > 50000 (Employee) )

2. Names of employees working in 'CSE':
   π name ( σ dname = 'CSE' (Employee ⋈ Dept) )

3. Students who have taken ALL courses:
   π roll, cid (Enrolls) ÷ π cid (Course)

Union Compatibility

For ∪, ∩ and −, both relations must have the same number of attributes with compatible domains.

Track your progress through the DBMS course