Relational Algebra & Calculus MCQs for the NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

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

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

Interactive quiz loading. The first 10 questions are shown below.

  1. What does the selection operator σ do in relational algebra?

    1. Renames a relation or its attributes
    2. Returns chosen attributes of every tuple
    3. Returns the tuples that satisfy a condition, keeping all attributes
    4. Combines every tuple of one relation with every tuple of another
    Show answer

    Answer: C. Returns the tuples that satisfy a condition, keeping all attributes

    Selection σ_condition(R) is a horizontal filter: it keeps whole tuples that satisfy the condition. Choosing columns is projection π, pairing all tuples is the Cartesian product ×, and renaming is ρ.

  2. In relational algebra, what does π_dept(EMP) return?

    1. The distinct dept values of EMP, because the result is a set
    2. The tuples of EMP whose dept is not NULL
    3. The number of distinct departments
    4. Every dept value, including duplicates, in table order
    Show answer

    Answer: A. The distinct dept values of EMP, because the result is a set

    Projection keeps only the listed attributes, and because a relation is a set, duplicate tuples are removed. SQL's SELECT dept keeps duplicates unless you write DISTINCT; this is a classic difference.

  3. Two relations must be union-compatible before R ∪ S, R ∩ S or R − S can be applied. What does that require?

    1. A common primary key attribute
    2. At least one tuple in common
    3. The same number of tuples
    4. The same degree, with compatible domains for corresponding attributes
    Show answer

    Answer: D. The same degree, with compatible domains for corresponding attributes

    Union compatibility (type compatibility) means both relations have the same number of attributes and each pair of corresponding attributes has the same domain. The tuple counts can differ freely.

  4. Which relational algebra operator is the natural choice for queries that say 'for all' or 'every', such as students who took every core course?

    1. Union (∪)
    2. Division (÷)
    3. Cartesian product (×)
    4. Selection (σ)
    Show answer

    Answer: B. Division (÷)

    R ÷ S returns the values in R that are paired with every tuple of S, which is exactly a 'for all' query. The other operators cannot express it alone.

  5. How does the natural join R ⋈ S decide which tuples to combine?

    1. It keeps tuples of R that have no match in S
    2. It equates all attributes with the same name in R and S and keeps one copy of each
    3. It matches on the primary key of R only
    4. It pairs every tuple of R with every tuple of S
    Show answer

    Answer: B. It equates all attributes with the same name in R and S and keeps one copy of each

    A natural join is an equijoin on every pair of same-named attributes, and the duplicate columns are dropped. Pairing everything is the Cartesian product, and keeping unmatched tuples is an outer join.

  6. What does the rename operator ρ allow you to do?

    1. Replace NULL values with defaults
    2. Give a new name to a relation or its attributes, for example to join a relation with itself
    3. Remove duplicate tuples
    4. Sort the tuples of a relation
    Show answer

    Answer: B. Give a new name to a relation or its attributes, for example to join a relation with itself

    ρ_S(B1, …, Bn)(R) renames R to S and its attributes to B1…Bn. It is needed for self-joins, where the same relation appears twice and the attribute names would otherwise clash.

  7. How is the theta join R ⋈_θ S defined in terms of basic operators?

    1. σ_θ(R × S)
    2. π_θ(R ∪ S)
    3. σ_θ(R) ∪ σ_θ(S)
    4. R × σ_θ(S)
    Show answer

    Answer: A. σ_θ(R × S)

    A theta join is a Cartesian product followed by a selection on the join condition θ. An equijoin is a theta join where θ uses only equality.

  8. What does the tuple relational calculus expression {t | EMP(t) ∧ t.salary > 50} return?

    1. All EMP tuples with salary above 50
    2. EMP tuples with salary 50 or less
    3. Only the salary attribute of EMP
    4. The number of employees earning above 50
    Show answer

    Answer: A. All EMP tuples with salary above 50

    In tuple relational calculus, t ranges over tuples of EMP and the formula keeps those with salary > 50. It is equivalent to σ_salary>50(EMP). Calculus says what to retrieve; algebra says how.

  9. Which set of operators is complete, meaning every other relational algebra operator can be expressed using only these?

    1. {σ, π, ⋈}
    2. {∪, ∩, −}
    3. {σ, π, ∪, ρ, −, ×}
    4. {σ, π, ∩, ÷}
    Show answer

    Answer: C. {σ, π, ∪, ρ, −, ×}

    Elmasri-Navathe give {σ, π, ∪, ρ, −, ×} as a complete set. Intersection, joins and division can all be rewritten with these. Without difference you cannot express negation, so the other sets fall short.

  10. Which expression always equals R ∩ S for union-compatible R and S?

    1. R ∪ (R − S)
    2. R − (R − S)
    3. S − (R − S)
    4. (R ∪ S) − R
    Show answer

    Answer: B. R − (R − S)

    R − S removes the common tuples from R, so subtracting that from R leaves exactly the common tuples. This is why intersection is not in the complete set: difference expresses it.

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.

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.