Skip to main content

Relational Algebra Cheat Sheet

·338 words·2 mins
Author
Alessandro Ferrini

We already discussed about Relational Algebra in a previous article. But if you’re preparing for an exam or technical interviews, here is a quick reference to efficiently navigate its various operations.

In this cheat sheet, we’ll summarize the most crucial relational algebra operations—including selections, projections, joins, and set operations—with clear examples and concise explanations.

Bookmark this page to have a handy reference for your database queries and SQL optimizations!


Basic Operations
#

OperationSymbolDescription
Selectionσcondition(R)Selects rows that satisfy a given predicate (like WHERE in SQL).
Projectionπattributes(R)Selects specified columns (removes duplicates).
Renamingρnew_name(R)Renames the relation or its attributes.

Set Operations
#

(Relations must be union-compatible – same number and type of attributes.)

OperationSymbolDescription
UnionR ∪ SCombines tuples from both R and S (removes duplicates).
Set DifferenceR − STuples in R but not in S.
IntersectionR ∩ STuples common to both R and S. (Can be derived as R − (R − S))

Cartesian Product (Cross Join)
#

OperationSymbolDescription
Cartesian ProductR × SCombines each tuple of R with every tuple of S. Results in a huge relation.

Joins
#

(Used to combine related tuples from different relations.)

OperationSymbolDescription
Theta JoinR ⨝θ SCombines tuples based on condition θ (e.g., R.A = S.B).
Equi JoinR ⨝R.A=S.B SA theta join using only =.
Natural JoinR ⨝ SAutomatically joins on all common attributes.
Outer Joins-Includes unmatched rows: Left ⟕, Right ⟖, Full ⟗

Division (÷)
#

OperationSymbolDescription
DivisionR ÷ SFinds tuples in R that are related to all tuples in S. Common in “for all” type queries.

Other Operations
#

OperationSymbolDescription
AssignmentTemporarily assigns the result of expressions to a variable.
Aggregate Functionsγfunction(R)Applies aggregation (COUNT, SUM, AVG, MIN, MAX) on grouped attributes.
Semi JoinR ⋉ S or R ⋊ SReturns tuples from R matching tuples in S based on a condition, without columns from S.