---
title: "The Relational Model and Relational Algebra"
description: "A table is a set of tuples over named attributes, and queries are built from a handful of operations on those sets: select, project, join, union, difference. Every query language sits on top of this a"
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-09-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 table is a set of tuples over named attributes, and queries are built from a handful of operations on those sets: select, project, join, union, difference. Every query language sits on top of this algebra, which is why the same question can be asked several ways and mean one thing.

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 rows over named columns. Each row, called a tuple, holds one value under each attribute. Because it is a set, each distinct row appears once, and the order of the rows means nothing.

Five operations build every query. Select keeps the rows that pass a test. Project keeps only the columns you name. Join pairs up rows from two tables. Union pours two tables into one. Difference keeps the rows that the other table lacks. Operations compose inside out, so the one closest to the table runs first.

**Example.** To get the names of students over 10, write π_name(σ_age>10(Students)). The select runs first and hands its rows to the project. Filtering each of R and S and then intersecting gives the same rows as intersecting first and filtering after, so one question can wear two writings. When two tables differ, project each side down to the shared columns before you intersect.

**Tip.** Before you write a union, check that both tables share the same attributes with matching types. And trust the set idea: a result never holds the same tuple twice, so a friend who reports a duplicate is describing something outside pure algebra.

**Recap.** Tables are sets of tuples, queries compose a few set operations, and equal results can come from different writings.

## 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)
- [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)
