SQL is relational algebra

Under the surface, SQL is the relational algebra from the last section:

  • SELECT columns: projection π
  • WHERE: filter σ
  • FROM several tables: product ×
  • UNION, INTERSECT, EXCEPT: union, intersection, difference

One difference matters: SQL keeps duplicates. Its tables are bags (multisets), not sets, so a row can appear many times unless you write SELECT DISTINCT.

Datalog relations are sets. The translation leans on that: against a database it uses SELECT DISTINCT, so duplicate rows never appear.