Relational Algebra, Tuple Calculus and Sql Pyqs for Gate Cs
Solve 11+ Relational Algebra, Tuple Calculus and Sql previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.
Try a question
Answer it here to see how it works. Nothing is recorded until you sign in.
Question 1
2026 Slot Set1 PYQ
Level 3: Exam Standard
Consider a relational database schema with two relations R(P,Q) and S(X,Y).
Let E={⟨u⟩∣∃v∃w⟨u,v⟩∈R∧⟨v,w⟩∈S} be a tuple relational calculus expression.
Which one of the following relational algebraic expressions is equivalent to E?
Question 2
2025 Slot Set2 PYQ
Level 3: Exam Standard
Consider the following relational schema:
Students (rollno: integer, name: string, age: integer, cgpa: real)
Which of the following options is/are correct SQL query/queries to retrieve the names of the students enrolled in course number (i.e., courseno) 1470?
Question 3
2025 Slot Set1 PYQ
Level 3: Exam Standard
Consider two relations describing teams and players in a sports league:
• teams(tid,tname): tid,tname are team-id and team-name, respectively • players(pid,pname,tid): pid,pname, and tid denote player-id, player-name and the team-id of the player, respectively
Which ONE of the following tuple relational calculus queries returns the name of the players who play for the team having tname as ‘MI’?
Question 4
2025 Slot Set1 PYQ
Level 3: Exam Standard
Consider the following database tables of a sports league.
An instance of the table and an SQL query are given.
SELECT MIN(P.age) FROM player P WHERE P.pid IN ( SELECT M.pid FROM team T, coach C, members M WHERE C.cname = 'Mark' AND T.cid = C.cid AND M.tid = T.tid )
The value returned by the given SQL query is ______. (Answer in integer)
Question 5
2024 Slot Set2 PYQ
Level 3: Exam Standard
The relation schema, Person(pid,city), describes the city of residence for every person uniquely identified by pid. The following relational algebra operators are available: selection, projection, cross product, and rename.
To find the list of cities where at least 3 persons reside, using the above operators, the minimum number of cross product operations that must be used is
Question 6
2024 Slot Set1 PYQ
Level 3: Exam Standard
Consider the following two relations, R(A,B) and S(A,C):
The total number of tuples obtained by evaluating the following expression
σB<C(R⋈R.A=S.AS)
is __________
Question 7
2022 PYQ
Level 3: Exam Standard
Consider the relational database with the following four schemas and their respective instances.
Student(sNo, sName, dNo) Dept(dNo, dName)
Course(cNo, cName, dNo) Register(sNo, cNo)
Student
sNo
sName
dNo
S01
James
D01
S02
Rocky
D01
S03
Jackson
D02
S04
Jane
D01
S05
Milli
D02
Dept
dNo
dName
D01
CSE
D02
EEE
Course
cNo
cName
dNo
C11
DS
D01
C12
OS
D01
C21
DE
D02
C22
PT
D02
C23
CV
D03
Register
sNo
cNo
S01
C11
S01
C12
S02
C11
S03
C21
S03
C22
S03
C23
S04
C11
S04
C12
S05
C11
S05
C21
SQL Query:
SELECT * FROM Student AS S WHERE NOT EXIST (SELECT cNo FROM Course WHERE dNo = “D01” EXCEPT SELECT cNo FROM Register WHERE sNo = S.sNo)
The number of rows returned by the above SQL query is___________.
Question 8
2022 PYQ
Level 3: Exam Standard
Consider the following three relations in a relational database.
Which of the following relational algebra expressions return the set of eIds who own all the brands?
Question 9
2021 Slot Set2 PYQ
Level 3: Exam Standard
The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department.
emp(empId, name, gender, salary, deptId)
Consider the following SQL query:
select deptId, count(*) from emp where gender = "female" and salary > (select avg(salary) from emp) group by deptId;
The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of
Question 10
2021 Slot Set1 PYQ
Level 3: Exam Standard
The following relation records the age of 500 employees of a company, where empNo (indicating the employee number) is the key:
empAge(empNo,age) Consider the following relational algebra expression:
ΠempNo(empAge⋈(age>age1)ρempNo1,age1(empAge)) What does the above expression generate?
Free preview ends here
Login to view the complete previous-year questions and solutions
Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.
Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.
Built around you, not around a syllabus PDF
Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.
Revision that hits your weak spots
We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.
Questions calibrated to the real exam
Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.
Notes written for recall, not for volume
Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.
One place for everything
Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.
Honest progress
No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.
Unlock the whole course
Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.
Relational Algebra, Tuple Calculus and Sql PYQs for GATE CS
Solve 11+ Relational Algebra, Tuple Calculus and Sql previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.
Chapter Roadmap: Relational Algebra, Tuple Calculus and SQL
Chapter Roadmap
Relational Algebra, Tuple Calculus and SQL
By the end of this chapter, you will master the translation between declarative query languages and procedural operations, write complex SQL aggregations, and estimate query execution costs.
1. Tuple Relational Calculus and RA Equivalence2 PYQs
Declarative querying, quantifiers, and translating TRC to Relational Algebra.
2. SQL Queries, Joins and Aggregation4 PYQs
Writing complex nested queries, group by, having, and various join types.
3. Relational Algebra Operations, Division and Self-Joins4 PYQs
Procedural query formulation, division operator, and self-join patterns.
4. Selection Cardinality and Query Result Estimation1 PYQ
Estimating the number of tuples returned by selections and joins.
Tuple Relational Calculus and RA Equivalence
Tuple Relational Calculus and RA Equivalence
Bridging the gap between declarative "what" and procedural "how" in database queries.
Context: Relational Algebra, Tuple Calculus and SQL > Tuple Relational Calculus and Relational Algebra Equivalence
What you will learn here:
The declarative syntax of Tuple Relational Calculus (TRC).
How existential and universal quantifiers map to relational algebra operations.
Step-by-step methods for translating TRC expressions into Relational Algebra.
Common traps involving free and bound variables.
Relational Algebra, Tuple Calculus and Sql: Solved Questions with Step-by-Step Explanations (10 Problems)
Question 1 · Databases · 2026_Set1MCQ
Consider a relational database schema with two relations R(P,Q) and S(X,Y).
Let E={⟨u⟩∣∃v∃w⟨u,v⟩∈R∧⟨v,w⟩∈S} be a tuple relational calculus expression.
Which one of the following relational algebraic expressions is equivalent to E?
A.
ΠP(R⋈R.P=S.XS)
B.
ΠP(S⋈S.X=R.QR)
C.
ΠP(R⋈R.P=S.YS)
D.
ΠP(S⋈S.Y=R.QR)
Correct Answer:
B
Step-by-Step Solution
Insight: This is a TRC to Relational Algebra translation question, recognizable by the set-builder notation and existential quantifiers linking two relations.
Exam route: Map the positional variables in the TRC tuples to the relation attributes. Identify the shared variable to find the join condition, then project the output variable.
Learning route:
Step 1: Analyze the schema. Relation R has attributes (P,Q) and relation S has attributes (X,Y).
Step 2: Analyze the first condition ⟨u,v⟩∈R. By positional mapping, the first variable u corresponds to attribute P, and the second variable v corresponds to attribute Q.
Step 3: Analyze the second condition ⟨v,w⟩∈S. By positional mapping, the first variable v corresponds to attribute X, and the second variable w corresponds to attribute Y.
Step 4: Identify the join condition. The variable v is shared between both tuples. Therefore, the value of R's second attribute must equal S's first attribute: R.Q=S.X.
Step 5: Identify the output. The expression outputs the tuple ⟨u⟩. Since u corresponds to the first attribute of R, we must project attribute P.
Step 6: Construct the Relational Algebra expression. We join R and S on R.Q=S.X and project P: ΠP(R⋈R.Q=S.XS).
Step 7: Match with options. Option B is ΠP(S⋈S.X=R.QR). Since the theta join is commutative, this is logically equivalent to our derived expression.
Final Answer: Option B.
Question 2 · Databases · 2025_Set2MSQ
Consider the following relational schema:
Students (rollno: integer, name: string, age: integer, cgpa: real)
Which of the following options is/are correct SQL query/queries to retrieve the names of the students enrolled in course number (i.e., courseno) 1470?
A.
<pre>SELECT S.name
FROM Students S
WHERE EXISTS (SELECT * FROM Enrolled E
WHERE E.courseno = 1470
AND E.rollno = S.rollno);</pre>
B.
<pre>SELECT S.name
FROM Students S
WHERE SIZEOF (SELECT * FROM Enrolled E
WHERE E.courseno = 1470
AND E.rollno = S.rollno) > 0;</pre>
C.
<pre>SELECT S.name
FROM Students S
WHERE 0 < (SELECT COUNT(*)
FROM Enrolled E
WHERE E.courseno = 1470
AND E.rollno = S.rollno);</pre>
D.
<pre>SELECT S.name
FROM Students S NATURAL JOIN Enrolled E
WHERE E.courseno = 1470;</pre>
Correct Answer:
["A","C","D"]
Step-by-Step Solution
Insight: This is a correlated subquery and join pattern question, recognizable because it asks to filter a parent table based on the existence of matching records in a child table.
Exam route: Evaluate each option for standard SQL validity and logical equivalence to "exists at least one enrollment for course 1470".
Learning route:
Step 1: Option A uses EXISTS with a correlated subquery. For each student, it checks if there is at least one row in Enrolled with courseno = 1470 and matching rollno. This is logically correct and standard SQL.
Step 2: Option B uses SIZEOF, which is not a valid SQL keyword or function for counting rows. Standard SQL uses COUNT. Thus, it is syntactically invalid.
Step 3: Option C uses a scalar subquery with COUNT(*) > 0. This correctly counts the enrollments for the student in course 1470 and returns true if the count is positive. This is logically equivalent to EXISTS and is valid SQL.
Step 4: Option D uses NATURAL JOIN. The only common attribute between Students and Enrolled is rollno. The natural join implicitly joins on rollno, and the WHERE clause filters for courseno = 1470. This correctly retrieves the names of enrolled students.
Final Answer: Options A, C, and D are correct.
Question 3 · Databases · 2025_Set1MCQ
Consider two relations describing teams and players in a sports league:
• teams(tid,tname): tid,tname are team-id and team-name, respectively • players(pid,pname,tid): pid,pname, and tid denote player-id, player-name and the team-id of the player, respectively
Which ONE of the following tuple relational calculus queries returns the name of the players who play for the team having tname as ‘MI’?
Insight: This is a Tuple Relational Calculus (TRC) translation question, recognizable by the set-builder notation and the need to map a natural language "join" condition into TRC syntax.
Exam route: Identify the free variable, the relations each variable ranges over, and the correct join condition linking them.
Learning route:
Step 1: The goal is to find the pname of players. Thus, the free variable p must range over the players relation, and the output is p.pname. This immediately eliminates options where p \in teams.
Step 2: We need to check the team name. This requires a second tuple variable, say t, ranging over the teams relation.
Step 3: To link the player to the team, we must enforce the foreign key relationship: p.tid = t.tid.
Step 4: We also need the specific condition: t.tname = 'MI'.
Step 5: Combining these with an existential quantifier (since we just need at least one such team, which is guaranteed to be unique by the schema, but logically it's an existence check), we get:
An instance of the table and an SQL query are given.
SELECT MIN(P.age) FROM player P WHERE P.pid IN ( SELECT M.pid FROM team T, coach C, members M WHERE C.cname = 'Mark' AND T.cid = C.cid AND M.tid = T.tid )
The value returned by the given SQL query is ______. (Answer in integer)
Correct Answer:
30.00
Step-by-Step Solution
Insight: This is a nested SQL query with an uncorrelated subquery using IN, recognizable by the aggregation MIN and the explicit join conditions in the subquery.
Exam route: Evaluate the subquery first to find the specific set of pids, then find the minimum age among those players in the outer query.
Learning route:
Step 1: Evaluate the innermost condition in the subquery: C.cname = 'Mark'. From the coach table, this gives cid = 102.
Step 2: Join with Team: T.cid = C.cid means T.cid = 102. From the team table, this gives tid = 20.
Step 3: Join with Members: M.tid = T.tid means M.tid = 20. Looking at the members table, the only row with tid = 20 has pid = 4.
Step 4: The subquery returns the singleton set {4}.
Step 5: The outer query selects MIN(P.age) from player where P.pid IN (4).
Step 6: The player with pid = 4 is Axar, whose age is 30.
Final Answer: 30.
Question 5 · Databases · 2024_Set2MCQ
The relation schema, Person(pid,city), describes the city of residence for every person uniquely identified by pid. The following relational algebra operators are available: selection, projection, cross product, and rename.
To find the list of cities where at least 3 persons reside, using the above operators, the minimum number of cross product operations that must be used is
A.
1
B.
2
C.
3
D.
4
Correct Answer:
B
Step-by-Step Solution
Insight: This is an "At Least N" self-join pattern question, recognizable by the phrase "at least 3 persons reside" and the available operators (cross product, rename).
Exam route: Recall the rule that finding at least N distinct matches requires N logical copies of the relation, which demands exactly N - 1 cross product operations.
Learning route:
Step 1: The goal is to find cities with ≥3 persons.
Step 2: To verify this using only cross product, selection, projection, and rename, we must create 3 logical copies of the Person relation: P1,P2,P3.
Step 3: Creating 3 copies from a single relation requires joining it with itself twice.
Step 4: The first cross product combines P1 and P2 (1 operation). The second cross product combines the result with P3 (1 operation).
Step 5: Total cross product operations = 3−1=2.
Step 6: We would then apply selections to ensure P1.city=P2.city=P3.city and P1.pid=P2.pid=P3.pid, followed by projection. But the question only asks for the number of cross products.
Final Answer: 2.
Question 6 · Databases · 2024_Set1NAT
Consider the following two relations, R(A,B) and S(A,C):
The total number of tuples obtained by evaluating the following expression
σB<C(R⋈R.A=S.AS)
is __________
Correct Answer:
2.00
Step-by-Step Solution
Insight: This is a multi-step relational algebra evaluation question, recognizable by the combination of a theta/natural join followed by a selection condition.
Exam route: First, compute the join R⋈R.A=S.AS to find all matching (A, B, C) tuples. Second, apply the selection σB<C to filter the joined result.
Learning route:
Step 1: Perform the join R⋈R.A=S.AS. We match rows where R.A=S.A.
R(10,20) matches S(10,90)→ Joined tuple: (10,20,90).
R(20,30) has no match in S.
R(30,40) matches S(30,45)→ Joined tuple: (30,40,45).
R(30,50) matches S(30,45)→ Joined tuple: (30,50,45).
R(50,95) has no match in S.
Step 2: The intermediate joined relation has 3 tuples: (10,20,90), (30,40,45), and (30,50,45).
Step 3: Apply the selection σB<C.
For (10,20,90): 20<90 is True. (Keep)
For (30,40,45): 40<45 is True. (Keep)
For (30,50,45): 50<45 is False. (Discard)
Step 4: Count the remaining tuples. There are exactly 2 tuples.
Final Answer: 2.
Question 7 · Databases · 2022NAT
Consider the relational database with the following four schemas and their respective instances.
Student(sNo, sName, dNo) Dept(dNo, dName)
Course(cNo, cName, dNo) Register(sNo, cNo)
Student
sNo
sName
dNo
S01
James
D01
S02
Rocky
D01
S03
Jackson
D02
S04
Jane
D01
S05
Milli
D02
Dept
dNo
dName
D01
CSE
D02
EEE
Course
cNo
cName
dNo
C11
DS
D01
C12
OS
D01
C21
DE
D02
C22
PT
D02
C23
CV
D03
Register
sNo
cNo
S01
C11
S01
C12
S02
C11
S03
C21
S03
C22
S03
C23
S04
C11
S04
C12
S05
C11
S05
C21
SQL Query:
SELECT * FROM Student AS S WHERE NOT EXIST (SELECT cNo FROM Course WHERE dNo = “D01” EXCEPT SELECT cNo FROM Register WHERE sNo = S.sNo)
The number of rows returned by the above SQL query is___________.
Correct Answer:
2.00
Step-by-Step Solution
Insight: This is a relational division query expressed in SQL using NOT EXISTS and EXCEPT, recognizable by the pattern "find entities that have all items of a certain type".
Exam route: Identify the target set (courses in D01: C11, C12). Find students registered for both. Count them.
Learning route:
Step 1: The subquery SELECT cNo FROM Course WHERE dNo = 'D01' yields the set {C11, C12}.
Step 2: The EXCEPT operator finds courses in D01 that a specific student S.sNo has NOT registered for.
Step 3: NOT EXISTS ensures that this EXCEPT result is empty. In other words, the student has registered for ALL courses in D01.
Step 4: Check each student against this condition:
S01: Registered for C11, C12. EXCEPT is empty. (Keep)
S02: Registered for C11. EXCEPT yields {C12}. (Discard)
Insight: This is a relational division question, recognizable by the phrase "own all the brands", which is the classic "for-all" universal quantification pattern.
Exam route: Identify the standard division operator form and its equivalent expansion using basic operators (Cartesian product and set difference).
Learning route:
Step 1: The goal is to find eId who own every bId present in the Brand relation. This is exactly Own÷Brand.
Step 2: Option A is the direct division expression: ΠeId(ΠeId,bId(Own)/ΠbId(Brand)). This is syntactically and logically correct.
Step 3: Option B is the standard expansion of division using basic operators: Candidates − Failures.
Candidates: ΠeId(Own) (all employees who own at least one brand).
All possible pairs: ΠeId(Own)×ΠbId(Brand).
Missing pairs: (All possible pairs) −ΠeId,bId(Own).
Failures (employees with missing pairs): ΠeId(Missing pairs).
Result: Candidates − Failures. This matches Option B exactly.
Step 4: Option C divides by ΠbId(Own), which only contains brands that are actually owned by someone. If a brand exists in Brand but is owned by no one, Option C would incorrectly ignore it, failing the "all brands" requirement.
Step 5: Option D creates a Cartesian product of ΠeId(Own) and ΠbId(Own), which generates spurious pairs not present in the actual Own relation, corrupting the division logic.
Final Answer: Options A and B are correct.
Question 9 · Databases · 2021_Set2MCQ
The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department.
emp(empId, name, gender, salary, deptId)
Consider the following SQL query:
select deptId, count(*) from emp where gender = "female" and salary > (select avg(salary) from emp) group by deptId;
The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of
A.
employees in the department.
B.
employees in the company.
C.
female employees in the department.
D.
female employees in the company.
Correct Answer:
B
Step-by-Step Solution
Insight: This is a SQL query with an uncorrelated scalar subquery in the WHERE clause, recognizable by the subquery having no reference to the outer query's tables.
Exam route: Analyze the subquery first. It calculates a single global value. Then see how the outer query uses it.
Learning route:
Step 1: Analyze the subquery: (select avg(salary) from emp). Since it has no WHERE clause linking to the outer query (no correlation), it is uncorrelated. It computes the average salary of ALL employees in the entire emp table (i.e., the company-wide average).
Step 2: Analyze the outer WHERE clause: gender = 'female' AND salary > (global average). This filters the emp table to only include female employees whose salary exceeds this company-wide average.
Step 3: Analyze the GROUP BY and SELECT: It groups these filtered employees by deptId and counts them (count(*)).
Step 4: Therefore, the query returns the number of female employees in each department whose salary is greater than the average salary of employees in the company.
Final Answer: Option B.
Question 10 · Databases · 2021_Set1MCQ
The following relation records the age of 500 employees of a company, where empNo (indicating the employee number) is the key:
empAge(empNo,age) Consider the following relational algebra expression:
ΠempNo(empAge⋈(age>age1)ρempNo1,age1(empAge)) What does the above expression generate?
A.
Employee numbers of only those employees whose age is the maximum.
B.
Employee numbers of only those employees whose age is more than the age of exactly one other employee.
C.
Employee numbers of all employees whose age is not the minimum.
D.
Employee numbers of all employees whose age is the minimum.
Correct Answer:
C
Step-by-Step Solution
Insight: This is a self-join pattern in relational algebra, recognizable by the rename operator ρ and a theta-join condition comparing an attribute with its renamed version.
Exam route: The condition age > age1 means the employee's age is strictly greater than the age of at least one other employee in the table. This is the logical definition of "not the minimum".
Learning route:
Step 1: The expression creates two logical copies of empAge: the original (with attributes empNo, age) and a renamed version (with attributes empNo1, age1).
Step 2: The theta-join ⋈age>age1 pairs every employee with every other employee who has a strictly smaller age.
Step 3: The projection ΠempNo extracts the employee numbers of the first copy (the ones with the larger age).
Step 4: If an employee's age is the absolute minimum in the table, there is no age1 strictly smaller than it. Thus, they will not participate in any join pair and will not appear in the result.
Step 5: Every other employee (whose age is not the minimum) will have at least one match (e.g., the employee with the minimum age), so they will appear in the result.