← back to databases

Relational Algebra

Wikipedia · wpRelational algebra · CC BY-SA 4.0

Relational algebra is a set of operations on relations that produce new relations. Six fundamental operations: select (filter rows), project (pick columns), union, difference, Cartesian product, and rename. Join is derived from these. Every SQL query compiles down to a relational algebra expression.

id name 1 Alice 2 Bob 3 Carol uid item 1 book 3 pen 1 lamp JOIN on id = uid Join: combine rows where keys match.

Select (sigma) — filter rows

Selection picks tuples that satisfy a predicate. It does not change the schema, only the cardinality. In SQL this is the WHERE clause.

Scheme

Project (pi) — pick columns

Projection picks a subset of attributes from each tuple. Duplicates are removed (relations are sets). In SQL this is the SELECT column list.

Scheme

Join — combine on matching values

A natural join pairs tuples from two relations that agree on shared attribute names. An equi-join matches on a specified condition. The join is the workhorse of relational queries: it reconstructs information that normalization split across tables.

Scheme

Union and difference — set operations

Union combines tuples from two union-compatible relations (same schema). Difference returns tuples in the first relation but not the second. Both require matching attribute names and domains.

Scheme
Neighbors

Cross-references

Foundations (Wikipedia)