---
title: "The Relational Model and Relational Algebra"
description: "A relation is a set of tuples over named attributes. Classical relational algebra combines selection, projection, join, union and difference to express queries. Different expressions can return the sa"
canonical: https://lightmysky.com/learn/computing/the-relational-model-and-relational-algebra-mt_unDBd_Ug8T
source: https://lightmysky.com/learn/computing/the-relational-model-and-relational-algebra-mt_unDBd_Ug8T.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# The Relational Model and Relational Algebra

A relation is a set of tuples over named attributes. Classical relational algebra combines selection, projection, join, union and difference to express queries. Different expressions can return the same relation.

Subject: Computing · Area: Data & Databases · Ages 18 to 19
Page: https://lightmysky.com/learn/computing/the-relational-model-and-relational-algebra-mt_unDBd_Ug8T

## Ready when they can

- Write a query as a composition of relational algebra operations
- Show two different algebra expressions that produce the same relation
- Explain what it means that a relation is a set rather than a list

## Lesson: Asking questions with sets of rows

A relation is a set of tuples over named attributes. Each tuple gives one value for each attribute. Row order does not matter, and each distinct tuple appears once. Two relations with the same schema are equal when they contain the same tuples. Every operation here returns a relation. SQL often retains duplicate rows unless distinct results are requested, so its usual duplicate rules differ.

Selection σ keeps whole tuples passing a test. Projection π keeps the named attributes and removes duplicate tuples created by dropping columns. In π_name(σ_age>16(Students)), evaluate the inner selection first, then project names. A test needs its attributes to remain available. The projection's attribute list is the result schema.

Here ⋈ means natural join. Pair tuples agreeing on every shared attribute, then combine their attributes, keeping each shared attribute once. Members(id,name) ⋈ Loans(id,book) matches on id. One member with two matching loan tuples contributes two combined tuples. Unmatched tuples contribute none. If two attributes are shared, both must match.

For R ∪ S, R ∩ S and R - S, use the same attribute names and matching types. Union keeps tuples in either relation. Intersection keeps tuples in both. Difference keeps tuples in R but not S. Union size is the two sizes added minus the shared count. Difference size is R's size minus the shared count. With no shared tuples, intersection is empty.

*(drawing: Each listed identifier represents one tuple in a one-attribute relation.)*

For compatible schemas, σ_a>7(R ∩ S) = σ_a>7(R) ∩ σ_a>7(S). Each expression keeps tuples that belong to R and S and have a above 7. Selection also distributes over union: filter the pooled tuples, or pool the separately filtered tuples. The test must be defined on both inputs. Difference is directional: R - S need not equal S - R.

Selection can move past projection when projection retains every attribute used by the test. Thus π_b(σ_b>7(R)) = σ_b>7(π_b(R)). Dropping b first would make its test undefined. Nested projections reduce to the final attributes if the inner projection retains them: π_a(π_a,b(R)) = π_a(R).

**Example.** Projection does not always distribute over intersection. Let R(a,b) contain (3,6) and S(a,b) contain (3,8). The full tuples differ, so R ∩ S is empty. Projecting each onto a gives {3} on both sides. Their intersection contains 3. Dropping b hid the difference between the original tuples.

Students(id,name,age) and Enrolled(id,course) share only id, a unique student identifier. To return name/course pairs for students over 16, filter Students, join Enrolled, then project name and course. To return only enrolled IDs of students over 16, use π_id(σ_age>16(Students)) ∩ π_id(Enrolled). Names alone may match different people.

A selection can move before a natural join when its test uses only attributes of that input. Here σ_age>16(Students ⋈ Enrolled) = σ_age>16(Students) ⋈ Enrolled. Both retain exactly the matching pairs whose student passes the age test. A test needing an attribute supplied only by Enrolled cannot run on Students alone.

**Recap.** Relations are sets. Check schemas, evaluate nested operations inside out, and justify equivalent expressions by the tuples they retain.

*This relational-algebra lesson, question bank and flashcards were written for this dataset.*

## Practice

20 questions on this page, each with its working shown.

## Needs first

- [SQL: Joining Tables and Summarising Groups](https://lightmysky.com/learn/computing/sql-joining-tables-and-summarising-groups-mt_0QPZDE2KuS)
- [Relational Databases: Tables, Keys and Relationships](https://lightmysky.com/learn/computing/relational-databases-tables-keys-and-relationships-mt_i7pZV6H902)

## Optional connections

- [Sets and Functions in the Language of Proof](https://lightmysky.com/learn/mathematics/sets-and-functions-in-the-language-of-proof-mt_XAcHX_3DVz)

## Opens up

- [Key-Value and Document Stores](https://lightmysky.com/learn/computing/key-value-and-document-stores-mt_PfBDSgfeQX)
- [Functional Dependencies and Boyce-Codd Normal Form](https://lightmysky.com/learn/computing/functional-dependencies-and-boyce-codd-normal-form-mt_PfWLq1aEQz)
