NIMCET, GATE, CUET & CBSE test series are live — start practicing free
syllabuzAI

Relational Algebra: Operators, Joins, Division | GATE CSE

Learn relational algebra operators, union compatibility, joins, division with basic operators and cardinality bounds for GATE CSE DBMS, with worked examples.

7 min read

AS

Aman Singh

Updated 26 November 2026

On this page

Quick answer: Relational algebra is a procedural query language. Its operators take relations and return relations, and results never contain duplicate tuples. The six basic operators are selection σ (rows that satisfy a condition), projection π (chosen columns), cross product ×, union ∪, set difference − and rename ρ. Derived operators include intersection (R − (R − S)), joins (theta, equi, natural and outer joins) and division ÷, which returns values of R paired with every tuple of S. Set operations need union-compatible relations.

GATE gives small relations and asks for the output or the number of tuples of an expression, or which expression answers an English query. This topic is part of the Relational Algebra and SQL chapter.

Basic operators

Selection σ

σP(R)\sigma_P(R) returns the tuples of R that satisfy condition P. It keeps all columns.

Projection π

πA1,…,Ak(R)\pi_{A_1, \dots, A_k}(R) returns only the listed columns and removes duplicate rows.

Example: R(A, B, C) = {(8, 4, 5), (2, 4, 5), (7, 4, 6), (3, 5, 5)}.

  • πB,C(R)\pi_{B,C}(R) = {(4, 5), (4, 6), (5, 5)}. The duplicate (4, 5) appears once.
  • σA>5(R)\sigma_{A>5}(R) = {(8, 4, 5), (7, 4, 6)}.

Cross product ×

R × S pairs every tuple of R with every tuple of S.

  • Degree (arity) of R × S = degree(R) + degree(S).
  • |R × S| = |R| × |S|. If either relation is empty, the product is empty.

Union, difference and intersection

For union-compatible R and S:

  • R ∪ S: tuples in either relation.
  • R − S: tuples in R but not in S.
  • R ∩ S = R − (R − S): tuples in both.

Union compatibility needs the same arity and the same domain for corresponding attributes. Attribute names can differ. For example, (Sid, Sname) and (StudID, StudName) are compatible, but (Sid, Sname) and (Sid, Marks) are not, because Sname and Marks have different domains.

Example: R(A) = {2, 3} and S(B) = {2, 4}. Then R ∪ S = {2, 3, 4}, R − S = {3} and R ∩ S = {2}.

Rename ρ

  • ρTemp(Stud)\rho_{Temp}(Stud) renames the relation to Temp.
  • ρI,N,A(Stud)\rho_{I,N,A}(Stud) renames all attributes.

Rename is needed for self-joins, where a relation is compared with itself.

Joins

JoinDefinition
Theta (conditional) joinσc(R×S)\sigma_c(R \times S)
Equi-joinA theta join whose condition uses only equality
Natural joinEquality on all common attribute names, keeping one copy of each
Left outer join (R ⟕ S)Natural join plus unmatched R tuples padded with NULLs
Right outer join (R ⟖ S)Natural join plus unmatched S tuples padded with NULLs
Full outer join (R ⟗ S)Union of the left and right outer joins

If R and S share no attribute names, their natural join is the same as their cross product.

Example: natural join of T1(A, B, C) and T2(B, C, D, E):

T1⋈T2=πA,B,C,D,E(σT1.B=T2.B ∧ T1.C=T2.C(T1×T2))T_1 \bowtie T_2 = \pi_{A,B,C,D,E}\big(\sigma_{T_1.B = T_2.B \,\wedge\, T_1.C = T_2.C}(T_1 \times T_2)\big)

Division ÷

R(A, B) ÷ S(B) returns the A values in R that are paired with every B value in S. It answers "for all" queries.

Division using basic operators

Query: students enrolled in every course, with E = Enroll(sid, cid) and C = Course(cid).

Step 1: Find students who miss at least one course. Build every possible (student, course) pair and remove the real enrollments:

πsid((πsid(E)×πcid(C))−πsid,cid(E))\pi_{sid}\big((\pi_{sid}(E) \times \pi_{cid}(C)) - \pi_{sid,cid}(E)\big)

Step 2: Subtract them from all enrolled students:

E÷C=πsid(E)−πsid((πsid(E)×πcid(C))−πsid,cid(E))E \div C = \pi_{sid}(E) - \pi_{sid}\big((\pi_{sid}(E) \times \pi_{cid}(C)) - \pi_{sid,cid}(E)\big)

Worked example

Enroll = {(s1, c1), (s1, c2), (s2, c1), (s3, c1), (s3, c2)} and Course = {c1, c2}.

Step 1: All pairs: {s1, s2, s3} × {c1, c2} gives 6 pairs.

Step 2: The only missing pair is (s2, c2), so the students missing a course are {s2}.

Step 3: Result = {s1, s2, s3} − {s2} = {s1, s3}.

"More than every" queries

Query: Emp(eid, sal, gen). Find women who earn more than every man.

Find the women who earn at most some man, then subtract them from all women:

πeid(σgen=F(Emp))−πT1.eid(σT1.gen=F ∧ T2.gen=M ∧ T1.sal≤T2.sal(ρT1(Emp)×ρT2(Emp)))\pi_{eid}(\sigma_{gen=F}(Emp)) - \pi_{T1.eid}\big(\sigma_{T1.gen=F \,\wedge\, T2.gen=M \,\wedge\, T1.sal \le T2.sal}(\rho_{T1}(Emp) \times \rho_{T2}(Emp))\big)

For "more than some man", a single self-join with the condition T1.sal > T2.sal is enough.

Cardinality bounds

Here R has n tuples and S has m tuples, all distinct.

ExpressionMinimumMaximum
R × Sn × mn × m
Natural join R ⋈ S0n × m
Left outer joinnn × m
Right outer joinmn × m
Full outer joinmax(n, m)n × m
R ∪ Smax(n, m)n + m
R ∩ S0min(n, m)
R − S0n
R ÷ S (m ≥ 1)0⌊n / m⌋

Useful equivalences

  • σP1∧P2(R)=σP1(σP2(R))\sigma_{P_1 \wedge P_2}(R) = \sigma_{P_1}(\sigma_{P_2}(R)), and selections can be applied in any order.
  • πA(πA,B(R))=πA(R)\pi_{A}(\pi_{A,B}(R)) = \pi_A(R), so only the outermost projection matters.
  • A selection that uses only R's attributes can be pushed inside a join: σP(R⋈S)=σP(R)⋈S\sigma_P(R \bowtie S) = \sigma_P(R) \bowtie S.
  • ∪ and ∩ are commutative and associative; − is neither.

Summary table

OperatorRemember
πRemoves duplicates
×Arity adds, cardinality multiplies
⋈ with no common attributesSame as ×
∩R − (R − S)
÷"For all"; at most ⌊n / m⌋ tuples
ρNeeded for self-joins

Exam tips

  • For "every" or "all" in the question, think division, or "all candidates minus those that fail for some".
  • For cardinality questions, check whether a key or foreign key limits the matches.
  • Before using a natural join, list the common attribute names. An accidental shared name changes the result.

Common mistakes

  • Keeping duplicates after projection. Relational algebra removes them.
  • Using a natural join when names match by accident. It equates every common name.
  • Writing division the wrong way round. The divisor's attributes must be a subset of the dividend's.
  • Ignoring union compatibility before applying set operators.

Practice questions

Q1. R(A, B) has 5 tuples and S(B, C) has 4. B is a key of S, and every R.B value appears in S. How many tuples are in R ⋈ S?

Answer: Each R tuple matches exactly one S tuple, so 5.

Q2. R has 6 tuples and S has 3. What is the maximum number of tuples in R ÷ S?

Answer: ⌊6 / 3⌋ = 2.

Q3. Write R ∩ S using only basic operators.

Answer: R − (R − S).

FAQs

What are the basic operators of relational algebra?

Selection, projection, cross product, union, set difference and rename. Every other operator can be built from these.

What is the difference between a natural join and an equi-join?

An equi-join can equate any chosen attributes and keeps both columns. A natural join equates all attributes with the same name and keeps one copy of each.

When is the division operator used?

For queries with "all" or "every", such as students enrolled in every course or suppliers who supply every part.

Does relational algebra allow duplicate tuples?

No. Relational algebra works on sets, so every result has distinct tuples.

Why is the rename operator needed?

It lets you refer to the same relation twice under different names, which you need for self-joins.

Conclusion

Relational algebra questions get mechanical once you know what each operator does to rows, columns and duplicates. Practise division and "every" queries, and learn the cardinality table. Continue with tuple relational calculus and SQL queries, or go back to the Relational Algebra and SQL chapter.

Concept Check

MEDIUM

Consider the following schedules involving two transactions. Which one of the following statements is TRUE?

S1S_1: r1(X);r1(Y);r2(X);r2(Y);w2(Y);w1(X)r_1(X); r_1(Y); r_2(X); r_2(Y); w_2(Y); w_1(X) S2S_2: r1(X);r2(X);r2(Y);w2(Y);r1(Y);w1(X)r_1(X); r_2(X); r_2(Y); w_2(Y); r_1(Y); w_1(X)

Suggested for you