Unary Operators in Relational Algebra: Selection and Projection Worked Examples
Learn selection and projection on one six-row EMPLOYEE relation. Follow each predicate, remove projected duplicates, compose operators, and avoid unsafe rewrites.
KnowledgeGate Team
Exam prep & CS education

Selection and projection are easy to swap in your head because both take one relation as input. The difference is structural: selection keeps chosen rows, while projection keeps chosen columns. On the six-row EMPLOYEE relation, selection produces two five-attribute tuples, projection produces five two-attribute tuples, and composition produces two Name-Salary tuples. Both operators recur across the wider CS fundamentals syllabus.
Selection and projection: the two unary operators
A unary relational-algebra operator consumes one relation. Selection is written as σ_condition(R). It applies a Boolean predicate to every tuple and returns the tuples for which that predicate is true. This produces a horizontal subset. Because every chosen row keeps the original attributes, selection may reduce cardinality, the number of tuples, but it does not change degree, the number of attributes.
Projection is written as π_attribute-list(R). It keeps only the named attributes, so it produces a vertical subset. Projection reduces or preserves degree. It can also reduce cardinality because relational algebra uses set semantics: if two projected tuples become identical, only one remains.
The SQL bridge is useful but not exact. A WHERE clause performs selection, and the SELECT list performs projection. SQL normally permits duplicate rows, so SELECT DISTINCT is required when its result must match pure relational algebra.
Worked selection: test the predicate row by row
The calculations use EMPLOYEE(Eid, Name, Dept, Salary, City). EMPLOYEE(Eid, Name, Dept, Salary, City) has degree 5 and cardinality 6.
Eid | Name | Dept | Salary | City |
|---|---|---|---|---|
101 | Asha | DB | 72000 | Delhi |
102 | Bharat | OS | 55000 | Pune |
103 | Charu | DB | 65000 | Delhi |
104 | Deepa | CN | 70000 | Jaipur |
105 | Eshan | DB | 58000 | Pune |
106 | Farah | OS | 62000 | Delhi |
Now compute σ_{Dept='DB' ∧ Salary≥60000}(EMPLOYEE) by testing both conditions for every row.
Eid | Department test | Salary test | Keep? |
|---|---|---|---|
101 | DB, pass | 72000 ≥ 60000, pass | Yes |
102 | OS, fail | 55000 < 60000, fail | No |
103 | DB, pass | 65000 ≥ 60000, pass | Yes |
104 | CN, fail | 70000 ≥ 60000, pass | No |
105 | DB, pass | 58000 < 60000, fail | No |
106 | OS, fail | 62000 ≥ 60000, pass | No |
Both tests pass only for Eid 101 and 103. The result contains the complete tuples (101, Asha, DB, 72000, Delhi) and (103, Charu, DB, 65000, Delhi). Its cardinality is 2, while its degree remains 5. Selection never quietly removes Eid, City, or another attribute.

Worked projection: keep columns, then remove duplicates
For π_{Dept,City}(EMPLOYEE), first copy the requested columns from every input tuple. Before duplicate elimination, the six pairs are:
(DB, Delhi), (OS, Pune), (DB, Delhi), (CN, Jaipur), (DB, Pune), (OS, Delhi)
The two (DB, Delhi) pairs came from Asha and Charu. They are identical after the other attributes are removed, so set semantics collapse them into one. The final relation is:
{(DB, Delhi), (OS, Pune), (CN, Jaipur), (DB, Pune), (OS, Delhi)}
The result therefore has degree 2 and cardinality 5. Projection did not test Salary or decide which employees qualified. It retained two attributes and then removed duplicate tuples. A reliable checking method is to list the requested columns, write every projected tuple, and only then cross out duplicates. Display order is not part of a relation.

Compose selection and projection, then translate to SQL
Evaluate π_{Name,Salary}(σ_{Dept='DB' ∧ Salary≥60000}(EMPLOYEE)) from the inside out. The inner selection is the calculation above, so it produces the complete Asha and Charu rows. The outer projection then keeps only Name and Salary, giving {(Asha, 72000), (Charu, 65000)}. The composed result has cardinality 2 and degree 2. The inner operator controls which rows reach the outer one. Projecting first would be unsafe if it discarded an attribute that the selection still needed.
Its set-semantics SQL counterpart is SELECT DISTINCT Name, Salary FROM Employee WHERE Dept = 'DB' AND Salary >= 60000;. These two output tuples happen to be unique, but DISTINCT makes the relational-algebra equivalence explicit. When you move from unary operations to queries involving two or more relations, continue with SQL queries and joins in DBMS.
Laws and safe rewrites: when operator order can change
Selection conditions can be composed or reversed. Starting with Dept='DB' gives Eid {101,103,105}, and then Salary≥60000 leaves {101,103}. Starting with Salary≥60000 gives {101,103,104,106}, and then the department test again leaves {101,103}. Thus both nested orders equal σ_{Dept='DB' ∧ Salary≥60000}(EMPLOYEE). This is selection commutativity and composition.
Nested projection also follows π_{Name}(π_{Name,Dept}(EMPLOYEE)) = π_{Name}(EMPLOYEE), returning all six names. The outer projection's attributes must still exist in the inner projection. But σ_{Dept='DB'}(π_{Name}(EMPLOYEE)) is invalid because Dept has already disappeared. A safe reduced-schema route is π_{Name}(σ_{Dept='DB'}(π_{Name,Dept}(EMPLOYEE))), which returns Asha, Charu, and Eshan. Selection, Projection, and Join Order Optimization in DBMS: Worked Example owns the multi-relation extension: it pushes filters and projections through a three-table plan and compares first-join sizes of 14, 8, and 4. The single-relation calculations here establish the legality checks those rewrites depend on.
Traps that change the answer
The first trap is reversing the meanings by saying that selection selects columns. Remember the shape check: selection can change cardinality but keeps degree, while projection changes degree and may also change cardinality. The second trap is forgetting that projection removes duplicate tuples under set semantics.
Another invalid move is placing a selection after a projection that removed its predicate attribute. Similarly, copying ordinary SQL output into a pure relational-algebra answer can retain duplicates unless the SQL uses DISTINCT. A relation also has no guaranteed tuple order. Do not import SQL NULL or three-valued logic into a classical algebra problem unless the question defines it.
Boolean precedence can separate answers. Dept='DB' OR (Salary≥70000 AND City='Delhi') keeps Eid {101,103,105}. In contrast, (Dept='DB' OR Salary≥70000) AND City='Delhi' keeps {101,103}. Eid 105 is the separating row because that tuple is in DB but not in Delhi. Finally, projection's duplicate removal is not database normalization, which addresses relation design and dependencies.
How exams test unary operators
Three useful practice shapes can be built from the same relation. First, compute the resulting tuples. Second, report cardinality and degree. Third, select the valid or equivalent expression after operators are reordered. The EMPLOYEE result sizes are 2 × 5 for selection, 5 × 2 for π_{Dept,City}, and 2 × 2 for the composed Name-Salary result.
Another question can ask you to translate between an algebraic expression and SQL. That exposes the set-versus-bag distinction: π_{Dept,City}(EMPLOYEE) contains five tuples, while SELECT Dept, City FROM Employee can display six rows. Adding DISTINCT gives the five-tuple set result.
Exam questions commonly vary the relation and predicate while testing the same tuple, cardinality, degree, and equivalence checks. KnowledgeGate has 20+ practice questions on this subtopic for applying those checks across different relations and predicates.
Short version and the next step
σ filters rows and keeps the schema. π keeps named columns and removes duplicate tuples under set semantics. Evaluate a composition inside out, and never apply a predicate after projecting away an attribute it needs.
For a broader core-CS learning sequence, continue with Zero to Hero. If your goal is placement-focused CS fundamentals, the Computer Science course is the closer fit. Then recompute all three results once without looking at the tables above.
Keep learning
Unary Operators (Selection and Projection) MCQs: 11 Solved Questions
Solve 11 past-paper MCQs on relational-algebra selection and projection, from recognising each operator to composing and transforming expressions safely.
Relational Algebra for GATE: Operators, Tuple-Counting and Query Equivalence Drills
Calculate set, join, and outer-join cardinalities on concrete relations, then use selection and projection pushdown without changing query meaning.
Division Operator in Relational Algebra: Worked DBMS Example and Exam Traps
Learn relational division by solving one student-course dataset three ways, then test your understanding against extra tuples, duplicates, and an empty divisor.
Query Languages in DBMS: Relational Algebra, SQL and a Worked Query
Follow one database request from plain English to relational algebra, intermediate relations, relational calculus and SQL, with every result traced.





