Relational Algebra & Calculus MCQs for the NSCT
Relational algebra is a set of operators that take relations as input and return a new relation: select (σ), project (π), the set operations, joins and division. Relational calculus describes the same queries without saying how to compute them. This is topic 5 of the 17 in the Databases area, which carries 10% of the NSCT according to HEC's Areas of Competencies. Candidates averaged 42.3% accuracy in Databases in 2026, per the HEC NSCT report.
Most questions give two small tables and ask what an expression returns, so the skill is tracing tuples carefully. The relations follow relational database concepts; the notation follows Elmasri-Navathe. Every result on this page was checked with a small Python implementation of each operator.
Select
Selection σ_condition(R) keeps the tuples that satisfy the condition and all their attributes. It is a horizontal filter, like SQL's WHERE.
With EMP(eid, name, dept, salary) holding salaries 60, 45, 50, 70, 55, 40 and 65, σ_salary>50(EMP) returns 4 tuples. The employee on exactly 50 is excluded.
Selections commute and combine: σ_c1(σ_c2(R)) = σ_c1 ∧ c2(R). Optimisers use this to push filters down a query tree.
Exam angle: check the boundary. Does the condition use > or ≥?
Project
Projection π_attribute-list(R) keeps the listed attributes. Because a relation is a set, duplicate result tuples are removed. If those 7 employees work in CS, EE and ME, π_dept(EMP) has 3 tuples. SQL's SELECT dept FROM emp returns 7 rows, because SQL keeps duplicates unless you add DISTINCT.
Order matters: π_name(σ_salary>50(EMP)) is valid, but σ_salary>50(π_name(EMP)) is not, because salary has already been projected away.
Exam angle: the algebra-versus-SQL duplicate difference is one of the most tested facts in this topic.
Set operations and rename
Union (∪), intersection (∩) and difference (−) need union-compatible relations: the same degree and matching domains. The Cartesian product (×) has no such rule.
| Expression | R(A) = {1, 2, 3, 4, 5}, S(A) = {4, 5, 6} |
|---|---|
| R ∪ S | {1, 2, 3, 4, 5, 6} |
| R ∩ S | {4, 5} |
| R − S | {1, 2, 3} |
| S − R | {6} |
| R × S | 15 tuples of degree 2 |
Difference is not commutative. Intersection is not needed as a basic operator, because R ∩ S = R − (R − S). Elmasri-Navathe give {σ, π, ∪, ρ, −, ×} as a complete set. Rename ρ gives a relation or its attributes new names, which you need for a self-join.
Exam angle: for |R| = 5 and |S| = 3, R ∪ S has between 5 and 8 tuples, and R − S has between 2 and 5.
Join
A theta join R ⋈_θ S is σ_θ(R × S). An equijoin uses only equality. A natural join R ⋈ S equates every pair of same-named attributes and keeps one copy of each.
Take R(A, B) = {(1, x), (2, y), (3, x), (4, z)} and S(B, C) = {(x, 10), (x, 20), (y, 30), (w, 40)}:
| Join | Tuples | Why |
|---|---|---|
| R ⋈ S | 5 | 1 and 3 match two x rows each, 2 matches y |
| R ⟕ S (left outer) | 6 | adds (4, z, NULL) |
| R ⟖ S (right outer) | 6 | adds (NULL, w, 40) |
| R ⟗ S (full outer) | 7 | adds both |
If R and S share no attribute names, R ⋈ S is the same as R × S.
Exam angle: a natural join matches on every shared name. If two tables both have a city column with different meanings, rows silently drop out.
Division
Division R ÷ S answers "for all" queries. For R(A, B) and S(B), it returns the A values paired with every B value in S.
| ENROL(sid, course) | CORE(course) |
|---|---|
| S1: DB, OS, CN | DB |
| S2: DB, OS | OS |
| S3: DB, OS, CN, AI | CN |
| S4: CN |
ENROL ÷ CORE = {S1, S3}. S3's extra AI course does not matter; S2 is missing CN. Using only basic operators:
R ÷ S = π_A(R) − π_A((π_A(R) × S) − R)
Exam angle: division is the answer whenever a question says "every" or "all". If S is empty, every A value in R qualifies.
Relational calculus
Tuple relational calculus (TRC) uses variables that range over tuples: {t | EMP(t) ∧ t.salary > 50}. Domain relational calculus (DRC) uses variables that range over attribute values. Both are non-procedural: they state what to retrieve, not how.
An expression is safe if its result is finite and drawn from the database. {t | ¬EMP(t)} is unsafe, because it describes every tuple that is not an employee. Codd showed that safe relational calculus and relational algebra have the same expressive power. A language with that power is relationally complete.
Exam angle: ∃ in calculus usually becomes a join in algebra, and ∀ usually becomes division.
Common traps
- Assuming π keeps duplicates. In relational algebra it never does.
- Projecting away an attribute and then selecting on it.
- Forgetting that natural join uses all common attributes, not just the one you intended.
- Writing σ_course≠'CS101' for "students who did not take CS101". That returns students with some other course. Use difference.
- Counting an outer join without its NULL-padded rows.
- Thinking π distributes over difference. π_A(R − S) can differ from π_A(R) − π_A(S).
Worked examples
1. Understanding. Which relational algebra operators require union-compatible operands: ×, ∪, ⋈ or −? Answer: ∪ and −, together with ∩. A Cartesian product or join can combine relations of any degree.
2. Application. R(a) = {2, 4, 6} and S(c) = {3, 5}. How many tuples does R ⋈_a>c S return? Answer: 3. The pairs are (4, 3), (6, 3) and (6, 5). The value 2 is not greater than either c.
3. Analysis. SUPPLY(sno, pno) = {(s1, p1), (s1, p2), (s2, p1), (s3, p2), (s3, p3)} and RED(pno) = {p1, p2}. A student writes π_sno(SUPPLY ⋈ RED) for "suppliers of every red part". What does it return, and what is correct? Answer: it returns {s1, s2, s3}, the suppliers of at least one red part. The correct expression, SUPPLY ÷ RED, returns {s1}, the only supplier with both p1 and p2.
Practise
The quiz below has 100 questions on relational algebra and calculus, filterable by tier and difficulty.
Practise: 100 questions
FAQs
What is the difference between relational algebra and relational calculus?
Relational algebra is procedural: an expression is a sequence of operations that says how to build the answer. Relational calculus is declarative: it describes the tuples you want with a logical formula. Safe relational calculus and relational algebra can express exactly the same queries.
How is relational algebra related to SQL?
SQL is based on both. WHERE is selection, the SELECT list is projection, and FROM with a join condition is a join. The main difference is that SQL works on multisets, so it keeps duplicates unless you write DISTINCT. SQL also adds aggregates, sorting and NULL handling.
Is there a DIVIDE operator in SQL?
No. SQL has no division keyword, so "for all" queries are written with a double NOT EXISTS ("there is no required item this supplier lacks"), or with GROUP BY and HAVING COUNT(DISTINCT …) equal to the number of required items.
Which joins should I know for the test?
Know the theta join, the equijoin and the natural join, and the three outer joins (left, right and full). Practise counting result tuples: inner joins drop unmatched tuples, while outer joins keep them and pad the missing side with NULLs.
Next step
Continue to Structured Query Language (SQL) MCQs to write these operations in SQL. For more problems, use relational algebra practice. Revisit the Databases MCQs hub or test yourself in an NSCT mock test.