Eroxl's Notes
Relational Algebra

Relational algebra is a procedural query language that defines a set of operations on relations. Each operation takes one or more relations as input and produces a new relation as output. This closure property means operations can be composed arbitrarily. Relational algebra serves as the theoretical foundation for query languages such as Structured Query Language.

Fundamental Operations

The six fundamental operations are sufficient to express any relational algebra query. All other operations can be derived from these.

Selection ()

Selects tuples from a relation that satisfy a given predicate.

where is a boolean predicate over attributes.

Example: returns all students older than 21.

Projection ()

Selects specified attributes from a relation, removing duplicates from the result.

Example: returns only the name and department of each employee.

Union ()

Returns all tuples that appear in either of two union-compatible relations.

Requires and to have the same arity and domain-compatible attributes.

Set Difference ()

Returns all tuples in the first relation that are not in the second.

Cartesian Product ()

Combines every tuple of one relation with every tuple of another.

where denotes the concatenation of the two tuples.

Rename ()

Renames either the relation or its attributes.

renames relation to with attributes renamed to .

Derived Operations

These operations can be expressed in terms of the fundamental operations but are used so frequently that they have their own notation.

Intersection ()

Returns tuples present in both relations.

Natural Join ()

Combines tuples from two relations that agree on all common attributes, then projects out the duplicate columns. The natural join is central to the theory of lossless-join decomposition.

Division ()

Returns tuples in that are associated with every tuple in . Useful for "for all" type queries.

Assignment ()

Assigns the result of a relational algebra expression to a temporary relation variable. This is purely notational convenience for breaking complex expressions into steps.

Properties

Property Operations
Commutative , , ,
Associative , , ,
Not commutative ,

Selection is idempotent: .

Selections can be cascaded: .

Projections can be cascaded: when .