← 🔣 Relational Algebra & Calculus
Subtopic 1 of 4

2.1Basic operators: σ, π, ∪, −, ×, ρ

The idea

Relational algebra is a small language of operators on tables. The core ones are σ (select rows), π (pick columns), ∪, −, × and ρ (rename).

Think of it like this: Spreadsheet tools: filter rows, hide columns, stack two sheets, subtract one sheet from another.

Why it exists

Every query language is judged against it, and exam questions ask what an expression returns.

How it works

  1. σ keeps the rows that satisfy a condition, all columns kept.
  2. π keeps some columns and removes duplicate rows.
  3. ∪, ∩, − need union-compatible tables (same number and types of columns).
  4. × pairs each row of R with each row of S: m·n rows.

Worked example: R has 4 rows, S has 3 rows. How many rows in R × S?

12 and the columns of both tables together.

Now play with it

  • →Run each operator in the lab and compare the input tables with the result.
  • →See how π collapses duplicate did values.
Emp
eidnamedid
1Asha10
2Ben20
3Chen10
4DiaNULL
→
Result: 2 rows
eidnamedid
1Asha10
3Chen10

Keeps rows, keeps all columns. Rows with NULL never satisfy a comparison.

Check yourself

π_A(R) where R(A, B) = {(1,x), (1,y), (2,x)} returns how many rows?

Remember: σ filters rows; π picks columns and removes duplicates; set operations need compatible tables.
Exam notes (the dense version)

σ selects rows, π picks columns (and removes duplicates), ∪ − ∩ need union-compatible relations, × pairs every row with every row, ρ renames. Relational algebra uses set semantics (no duplicates). Everything else (∩, joins, division) can be derived from σ π ∪ − ×.

Previous year questions: Relational Algebra & Calculus (12)

PYQs are grouped by topic, so this is the full set for Relational Algebra & Calculus; try the ones that match this subtopic. Open all 12 on the topic page.