Selection
Selection
Definition
Selection (symbol: σ, sigma) is the relational algebra operation that picks a SUBSET OF ROWS from a relation based on a condition — it never removes or adds columns, only rows. σ(gpa >= 3.5)(Students) reads as "select the rows of Students where gpa >= 3.5."
How It Works
Selection maps directly onto SQL's WHERE clause:
sqlSELECT id, name, department, gpa FROM students WHERE gpa >= 3.5 ORDER BY id;
The algebraic notation σcondition(Relation) and the SQL WHERE clause express exactly the same idea: filter rows, keep the full row shape (same columns) for every row that passes. Selection is one of the two most fundamental relational algebra operations, alongside Projection (7.2) — nearly every real query is built by combining these two with joins.
Edge Cases and Pitfalls
- Selection is often confused with Projection because both "narrow down" a relation — but Selection narrows ROWS (keeps all columns, fewer rows), while Projection narrows COLUMNS (keeps all matching rows, fewer columns). They answer different questions: "which rows?" vs. "which columns?"
- A selection condition involving
NULLfollows three-valued logic (see Chapter 8's NULL Semantics) —σ(department = NULL)is not how you select rows with a missing department; that requires the SQL-specificIS NULLtest, which doesn't have a clean pure-relational-algebra equivalent in the classic (NULL-free) formulation of the algebra. - Multiple selection conditions can be combined with AND/OR, corresponding to combining SQL
WHEREconditions the same way:σ(gpa >= 3.5 AND department = 'Engineering')(Students).
Key Takeaways
- Selection (σ) filters rows by a condition; SQL's
WHEREclause is its direct equivalent. - It never changes which columns appear — only which rows survive.
- Selection and Projection are the two foundational, complementary "narrowing" operations of relational algebra.