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

Relational Algebra and SQL in DBMS | GATE CSE

Chapter overview of relational algebra, tuple relational calculus and SQL for GATE CSE DBMS: operators, division, cardinality bounds and SQL execution order.

5 min read

AS

Aman Singh

Updated 26 November 2026

On this page

Quick answer: Relational query languages come in two styles. Relational algebra is procedural: it says how to get the result, using operators such as selection σ, projection π, cross product ×, union ∪, difference −, rename ρ, and the derived join ⋈, intersection ∩ and division ÷. It always returns distinct tuples. Relational calculus (tuple and domain) is non-procedural: it says only what to retrieve. SQL is the practical language. SELECT-FROM-WHERE corresponds to π(σ(R₁ × … × Rₙ)), and SQL adds GROUP BY, HAVING, nested subqueries, IN, ANY, ALL and EXISTS. Safe TRC, safe DRC and basic relational algebra are equally expressive.

GATE asks you to evaluate relational algebra expressions and SQL queries on small tables, find result sizes, and spot equivalent queries. This chapter page maps the area and links to the detailed notes.

Chapter overview

TopicKey ideasDetailed notes
Relational algebraBasic and derived operators, joins, division, union compatibility, cardinalityRelational algebra
Tuple relational calculusSyntax, quantifiers, safe expressions, equivalence to relational algebraTuple relational calculus
SQLExecution order, GROUP BY and HAVING, nested and correlated queries, IN, ANY, ALL, EXISTS, NULLsSQL queries

Procedural vs non-procedural

ProceduralNon-procedural
Says how to compute the result as well as what to retrieveSays only what to retrieve
Relational algebraTuple and domain relational calculus

Relational algebra in brief

OperatorSymbolType
SelectionσBasic
ProjectionπBasic
Cross product×Basic
Union∪Basic
Set difference−Basic
RenameρBasic
Intersection∩, equal to R − (R − S)Derived
Join⋈, a selection over ×Derived
Division÷, built from π, × and −Derived

Union, intersection and difference need union-compatible relations: the same number of attributes, with matching domains.

Cardinality bounds

R has n tuples and S has m tuples.

ExpressionNumber of tuples
R × Sn × m
Natural join0 to n × m
Left outer joinn to n × m
Right outer joinm to n × m
Full outer joinmax(n, m) to n × m
R ∪ Smax(n, m) to n + m
R ∩ S0 to min(n, m)
R − S0 to n
R ÷ S0 to ⌊n / m⌋

SQL in brief

  • Written order: SELECT [DISTINCT] … FROM … WHERE … GROUP BY … HAVING … ORDER BY.
  • Execution order: FROM → WHERE → GROUP BY → HAVING → SELECT → DISTINCT → ORDER BY.
  • SQL keeps duplicates unless you use DISTINCT, while relational algebra always removes them.
  • WHERE filters rows; HAVING filters groups.
  • For single-column comparisons, IN means = ANY and NOT IN means <> ALL.
  • EXISTS checks whether a subquery returns any row.

Worked example

Question: Enroll(sid, cid) and Course(cid). Write a relational algebra expression for "students enrolled in every course".

Step 1: With division:

πsid,cid(Enroll)÷πcid(Course)\pi_{sid,cid}(Enroll) \div \pi_{cid}(Course)

Step 2: With basic operators only:

πsid(Enroll)−πsid((πsid(Enroll)×πcid(Course))−πsid,cid(Enroll))\pi_{sid}(Enroll) - \pi_{sid}\big((\pi_{sid}(Enroll) \times \pi_{cid}(Course)) - \pi_{sid,cid}(Enroll)\big)

The inner part finds (student, course) pairs that are missing. Subtracting those students from all enrolled students leaves the ones who took every course.

Summary table

LanguageStyleDuplicatesTypical GATE question
Relational algebraProceduralRemoved (sets)Output or size of an expression
Tuple / domain calculusDeclarativeNot applicable (sets)Which expression matches an English query
SQLDeclarativeKept unless DISTINCTOutput of a query on a given table

Exam tips

  • For relational algebra, think in sets and practise division.
  • For SQL, trace the query in execution order and watch for NULLs and duplicates.
  • "Every" or "all" in a question usually points to division, ∀ in calculus, or NOT EXISTS in SQL.

Common mistakes

  • Forgetting that relational algebra removes duplicates while SQL does not.
  • Applying set operations to relations that are not union compatible.
  • Putting aggregate conditions in WHERE. They belong in HAVING.
  • Treating NOT IN and NOT EXISTS as the same when NULLs can appear.

Practice questions

Q1. R has 4 tuples and S has 3. What are the maximum and minimum sizes of R ∪ S?

Answer: Maximum 7, minimum 4.

Q2. What does SELECT A FROM R WHERE P translate to in relational algebra?

Answer: πA(σP(R))\pi_A(\sigma_P(R)), except that SQL keeps duplicates.

Q3. Can a HAVING condition use a column that is neither grouped nor aggregated?

Answer: No, not in standard SQL. HAVING conditions must use grouping columns or aggregate functions.

FAQs

What is the difference between relational algebra and relational calculus?

Relational algebra is procedural and describes a sequence of operations. Relational calculus is declarative and describes the properties of the tuples you want.

What is the division operator used for?

Queries that contain "all" or "every", such as students enrolled in every course.

Does SQL remove duplicate rows?

Not by default. SELECT DISTINCT removes them, and UNION, INTERSECT and EXCEPT remove them unless you add ALL.

What is the difference between WHERE and HAVING?

WHERE filters individual rows before grouping. HAVING filters groups after GROUP BY.

Are relational algebra and relational calculus equally powerful?

Yes. Basic relational algebra, safe tuple relational calculus and safe domain relational calculus can express the same queries.

Conclusion

Work through the detailed notes on relational algebra, tuple relational calculus and SQL queries. For schema design, see Normalization.

Concept Check

EASY

Consider the following statements S1 and S2 about the relational data model:

S1: A relation scheme can have at most one foreign key. S2: A foreign key in a relation scheme R cannot be used to refer to tuples of R.

Which one of the following choices is correct?

Suggested for you