LightMySky

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.

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • 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

1 · Read

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.

Try it together

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.

Good to know

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.

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

2 · Watch

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Then practise

8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Spotted a problem on this page? Tell us
The Relational Model and Relational Algebra · Computing, ages 18 to 19 · LightMySky