Relational Algebra Selection: A First Look
Think of a railway reservation counter. The clerk has a massive register listing every train, every date, every coach, and every passenger. Now, a passenger walks in and says, "I want to see only the trains going to Delhi on 15th December." The clerk does not read out the entire register. Instead, he flips through, picks out only those rows that match "destination = Delhi" and "date = 15th December," and shows you just those.
That act of picking specific rows from a table based on a condition is exactly what Selection does in relational algebra.
The Core Idea
Selection is the operation that chooses rows from a relation (a table) that satisfy a given condition. It is like a filter — you pass a table through it, and only those rows that meet your criteria come out the other side. Everything else is discarded.
The condition you specify is called a predicate. It is a simple test that each row is checked against. For example:
- "City is 'Mumbai'"
- "Age is greater than 18"
- "Status is 'Active'"
Only rows for which the predicate is true are kept. Rows where it is false are removed.
Why It Matters
In the real world, data tables are enormous. A bank's transaction table might have millions of rows. A school's student database might have thousands. You never want to work with the entire table at once — you want only the relevant subset. Selection is how you get that subset.
The NCERT textbook (Class 12 Computer Science, Chapter on Database Concepts) introduces Selection as one of the fundamental operations of relational algebra. It states that Selection is used to retrieve tuples (rows) that satisfy a specific condition. The textbook emphasises that Selection works on a single relation and produces another relation (a subset of rows) as its result.
Key Points to Remember
- Selection reduces the number of rows, not columns. The output has the same columns as the input, but fewer rows.
- The condition can involve comparisons: equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to.
- Conditions can be combined using logical operators like AND, OR, and NOT. For instance: "City = 'Delhi' AND Age > 18" selects rows that satisfy both conditions.
- The result of a Selection is itself a relation — so you can apply further operations on it.
Selection is often confused with Projection. The difference is simple: Selection picks rows (horizontal filtering), while Projection picks columns (vertical filtering). If you want only certain columns, that is Projection. If you want only certain rows, that is Selection. If you want both, you apply Selection first, then Projection.
A Simple Example (Without Numbers)
Imagine a table called Students with columns: RollNo, Name, City, and Grade.
If you want to see only those students who live in "Pune," you apply Selection with the condition "City = 'Pune'." The result is a new table that has the same four columns, but only the rows where the City column contains "Pune." …