Relational Algebra

Unary Operations

Projection: πα\pi_{\alpha}

  • Given a list of column names α\alpha and a relation R, we extract columns from the relation

  • Subset of columns

  • SQL

    • SELECT DISTINCT col1, col2

    • FROM r

Selection: σθ\sigma_{\theta}

  • Unary operator

  • Filter to select rows of a relation where a condition is satisfied

  • SQL

    • SELECT DISTINCT *

    • FROM r

    • WHERE col=‘val’

Rename: ρα\rho_{\alpha}

  • Does not change the instance, only the schema

Binary Operations

Cartesian Product X

  • Join: variety of operations that connect two relations

  • RxS concatenates every tuple in R with every tuple in S

  • SQL

Join ⋈θ\bowtie_{\theta}

Natural Join

Union U

  • If two relations have the same structure, they are union-compatible and we can perform set operations

Difference

  • Returns items not in two tables