Meaning and assumptions
Relational algebra describes database queries as operations on relations with explicit set semantics. Selection chooses rows, projection chooses columns and removes duplicate result tuples. A join combines tuples under a condition. SQL often retains duplicates unless DISTINCT is requested.[1]
Finite relations with unambiguous attribute names and an explicit join condition. Classical relational algebra is considered here without NULL. Translation into SQL requires separate attention to duplicates, NULL and outer joins.[1]
Why the approach works
A theta join can be understood as a Cartesian product followed by selection. This explains the upper bound |R||S|: the result cannot contain more than all possible tuple pairs. When a foreign key refers to a unique key, each matching left tuple has at most one partner. A one-to-many join can instead make a left row appear repeatedly. Projection then changes the visible attributes; under set semantics previously distinct tuples can collapse into one. Row ordering is not a property of a relation.[1]
Two complete worked examples
Join learners to their courses
- Given
- R(id, name)={(1, Ada),(2, Ben),(3, Cora)}; S(id, course)={(1, Maths),(1, Physics),(2, Chemistry)}. Join by ID and project onto one ID, name and course.
- Find
- Result
Test equality of IDs for every pair.
Retain only the three matching pairs.
Result: Result:{(1, Ada, Maths),(1, Ada, Physics),(2, Ben, Chemistry)}. Cora is absent from the inner join.
Check: Ada has two enrolments, Ben one and Cora none;2+1+0=3 result tuples.
Projection and SQL duplicates
- Given
- Use the previous join result and output only names.
- Find
- Result
Project onto name under set semantics.
Explicitly remove duplicates for the same result in SQL.
Result: Result: relational projection returns Ada and Ben once each. SQL SELECT name initially retains Ada twice; SELECT DISTINCT name removes the duplicate.
Check: The two Ada rows differ by course before projection, but not after it.
Recall the method later with the formula’s flashcards.
10 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Five exercises with solutions
Calculate · Application
Select the row with id=2 from R.
Show hint
State the approach and assumptions before substituting.
Learning goal: Select the row with id=2 from R.
Show solution and calculation
σid=2(R)={(2, Ben)}.
Selection changes row count here, not attributes.
Calculate · Application
How many tuples does R×S contain in the example?
Show hint
State the approach and assumptions before substituting.
Learning goal: How many tuples does R×S contain in the example?
Show solution and calculation
|R|×|S|=3×3=9 tuple pairs before join selection.
Error analysis · Application
Must an inner join always return exactly as many rows as R?
Show hint
State the approach and assumptions before substituting.
Learning goal: Must an inner join always return exactly as many rows as R?
Show solution and calculation
No.
Unmatched tuples disappear and multiple matching partners repeat left rows.
In the example Cora has0 partners and Ada has2.
Transfer · Challenge
What changes for Cora in a left outer join?
Show hint
State the approach and assumptions before substituting.
Learning goal: What changes for Cora in a left outer join?
Show solution and calculation
SQL retains Cora in an extra row with a missing right-side course, usually NULL.
This differs from the formally defined inner join used here.
Interpret · Application
Does SELECT DISTINCT name guarantee alphabetical order?
Show hint
State the approach and assumptions before substituting.
Learning goal: Does SELECT DISTINCT name guarantee alphabetical order?
Show solution and calculation
No.
DISTINCT removes duplicates; guaranteed output order requires ORDER BY.
Check your understanding with the formula’s reference test.
4 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Related next steps
Sources for this explanation
Quanta · Updated November 6, 2026
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Locally authored DE/EN article with two original examples, five exercises, model limits and a native diagram.
Cite this reference page
Quanta. Relational algebra: selection, projection and join. Updated November 6, 2026. https://quanta-study.de/en/formula-sheet/relationale-algebra-datenbanken
When citing a specific scientific statement, also cite the specialist source linked to that statement.