Projection
Projection
Definition
Projection (symbol: π, pi) is the relational algebra operation that picks a SUBSET OF COLUMNS from a relation, discarding the rest — it never removes rows (except that resulting duplicate rows are eliminated, since a relation is formally a SET of tuples). π(name, department)(Students) reads as "project Students onto just the name and department columns."
How It Works
Projection maps onto SQL's column list in SELECT:
sqlSELECT DISTINCT department FROM students;
Note the DISTINCT: pure relational algebra projection removes duplicate resulting rows automatically (since a relation is a set — no duplicate tuples are allowed), but SQL's SELECT does NOT remove duplicates by default (SQL relations are technically multisets/bags, not pure sets) — DISTINCT is needed to make a SQL query behave like a textbook projection.
Edge Cases and Pitfalls
- This SQL-vs-algebra duplicate-handling difference is one of the most commonly tested "gotcha" facts about Projection:
π(department)(Students)in pure relational algebra always yields distinct department values, while plainSELECT department FROM studentsin SQL can return the same department many times over. - Projecting onto a set of columns that happens to include a candidate key produces a result with the same number of rows as the input (no duplicates possible, since the key values were already unique) — projecting onto NON-key columns is where duplicate elimination actually becomes visible.
- Projection and Selection are commonly chained together (project after selecting, or vice versa) to answer real questions: "which departments have at least one student with gpa >= 3.5?" is a Selection followed by a Projection.
Key Takeaways
- Projection (π) picks a subset of columns; SQL's
SELECT <columns>is its direct equivalent. - Pure algebraic projection removes duplicate rows automatically (sets); SQL needs an explicit
DISTINCTto match that behavior. - Projection and Selection are typically combined to answer realistic questions.