Introduction

Relational algebra is a formal query language used to manipulate and retrieve data from relational databases using mathematical set-based operations.

Core Operators

Selection (σ)

  • Syntax:
  • Meaning: Selects rows (tuples) in relation that satisfy condition c
  • Properties:
    • Output schema = input schema
    • Output may have fewer rows
    • Condition c must use attributes from R only

Projection (π)

  • Syntax:
  • Meaning: Keeps only specified attributes (columns) in list , in order
  • Properties:
    • May remove duplicate rows (relations are sets)
    • No duplicate attributes or expressions allowed in
    • must reference attributes from

Renaming (ρ)

  • Syntax:
  • Meaning: Renames attributes in R using mapping
  • Properties:
    • Only attribute names change; data and column order remain unchanged
    • No duplicate target names
    • No attribute renamed more than once

Set Operators

Union Compatibility

Relations and are union-compatible if:

  • They have the same number of attributes
  • Corresponding attributes have same or compatible domains
  • Attribute order matters

Cross Product (Cartesian Product)

  • Syntax:
  • Meaning: Combines every tuple of with every tuple of
  • Output: All attributes of followed by all attributes of
  • Size:
  • ⚠️ Attribute names must be unique across and
  • Often followed by selection + projection to refine the result

Join Operators

Joins combine cross product + selection + projection for meaningful combinations of related tuples.

Theta Join (θ-join)

  • Syntax:
  • General condition-based join

Equi Join

  • Special case of -join where only involves equality ()

Natural Join

  • Syntax:
  • Joins on all common attributes (same name and domain)
  • Common columns appear only once
  • If no common attributes → behaves like cross product

Outer Joins

Include unmatched tuples from one or both relations.

  1. Left Outer Join (): All tuples from + matched from
  2. Right Outer Join (): All tuples from + matched from
  3. Full Outer Join (): All tuples from both, matched or not
  4. Natural Outer Joins: Apply outer join semantics using natural join criteria