chapter

    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 and .

    Let be a tuple relational calculus expression.

    Which one of the following relational algebraic expressions is equivalent to ?
    Question 2
    2025 Slot Set2 PYQ
    Level 3: Exam Standard
    Consider the following relational schema:

    Students (rollno: integer, name: string, age: integer, cgpa: real)

    Courses (courseno: integer, cname: string, credits: integer)

    Enrolled (rollno: integer, courseno: integer, grade: string)

    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 and in a sports league:

    • : are team-id and team-name, respectively
    • : , and 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 as ‘’?
    Question 4
    2025 Slot Set1 PYQ
    Level 3: Exam Standard
    Consider the following database tables of a sports league.

    player(pid,pname,age)                    team(tid,tname,city,cid)
    coach(cid,cname)                           members(pid,tid)

    An instance of the table and an SQL query are given.

    playercoachteammemberspidpnameage1Jasprit312Atharva243Ishan264Axar30cidcname101Ricky102Mark103Trevortidtnamecitycid10MIMumbai10220DCDelhi10130PKMohali103pidtid110230310420

    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, and :

    R A B 10 20 20 30 30 40 30 50 50 95 S A C 10 90 30 45 40 80
    The total number of tuples obtained by evaluating the following expression 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
    sNosNamedNo
    S01JamesD01
    S02RockyD01
    S03JacksonD02
    S04JaneD01
    S05MilliD02

    Dept
    dNodName
    D01CSE
    D02EEE

    Course
    cNocNamedNo
    C11DSD01
    C12OSD01
    C21DED02
    C22PTD02
    C23CVD03

    Register
    sNocNo
    S01C11
    S01C12
    S02C11
    S03C21
    S03C22
    S03C23
    S04C11
    S04C12
    S05C11
    S05C21


    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 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:


    Consider the following relational algebra expression:


    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.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    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 Equivalence 2 PYQs

    Declarative querying, quantifiers, and translating TRC to Relational Algebra.

    2. SQL Queries, Joins and Aggregation 4 PYQs

    Writing complex nested queries, group by, having, and various join types.

    3. Relational Algebra Operations, Division and Self-Joins 4 PYQs

    Procedural query formulation, division operator, and self-join patterns.

    4. Selection Cardinality and Query Result Estimation 1 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_Set1 MCQ
    Consider a relational database schema with two relations and .

    Let be a tuple relational calculus expression.

    Which one of the following relational algebraic expressions is equivalent to ?
    1. A.

    2. B.

    3. C.

    4. D.

    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 has attributes and relation has attributes .

    Step 2: Analyze the first condition . By positional mapping, the first variable corresponds to attribute , and the second variable corresponds to attribute .

    Step 3: Analyze the second condition . By positional mapping, the first variable corresponds to attribute , and the second variable corresponds to attribute .

    Step 4: Identify the join condition. The variable is shared between both tuples. Therefore, the value of 's second attribute must equal 's first attribute: .

    Step 5: Identify the output. The expression outputs the tuple . Since corresponds to the first attribute of , we must project attribute .

    Step 6: Construct the Relational Algebra expression. We join and on and project : .

    Step 7: Match with options. Option B is . Since the theta join is commutative, this is logically equivalent to our derived expression.

    Final Answer: Option B.

    Question 2 · Databases · 2025_Set2 MSQ
    Consider the following relational schema:

    Students (rollno: integer, name: string, age: integer, cgpa: real)

    Courses (courseno: integer, cname: string, credits: integer)

    Enrolled (rollno: integer, courseno: integer, grade: string)

    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?
    1. A.

      <pre>SELECT S.name

      FROM Students S

      WHERE EXISTS (SELECT * FROM Enrolled E

      WHERE E.courseno = 1470

      AND E.rollno = S.rollno);</pre>

    2. 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>

    3. C.

      <pre>SELECT S.name

      FROM Students S

      WHERE 0 &lt; (SELECT COUNT(*)

      FROM Enrolled E

      WHERE E.courseno = 1470

      AND E.rollno = S.rollno);</pre>

    4. 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_Set1 MCQ
    Consider two relations describing and in a sports league:

    • : are team-id and team-name, respectively
    • : , and 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 as ‘’?
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    A

    Step-by-Step Solution

    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:

    This exactly matches Option A.

    Final Answer: Option A.

    Question 4 · Databases · 2025_Set1 NAT
    Consider the following database tables of a sports league.

    player(pid,pname,age)                    team(tid,tname,city,cid)
    coach(cid,cname)                           members(pid,tid)

    An instance of the table and an SQL query are given.

    playercoachteammemberspidpnameage1Jasprit312Atharva243Ishan264Axar30cidcname101Ricky102Mark103Trevortidtnamecitycid10MIMumbai10220DCDelhi10130PKMohali103pidtid110230310420

    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_Set2 MCQ
    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
    1. A.

      1

    2. B.

      2

    3. C.

      3

    4. 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 persons.

    Step 2: To verify this using only cross product, selection, projection, and rename, we must create 3 logical copies of the Person relation: .

    Step 3: Creating 3 copies from a single relation requires joining it with itself twice.

    Step 4: The first cross product combines and (1 operation). The second cross product combines the result with (1 operation).

    Step 5: Total cross product operations = .

    Step 6: We would then apply selections to ensure and , followed by projection. But the question only asks for the number of cross products.

    Final Answer: 2.

    Question 6 · Databases · 2024_Set1 NAT
    Consider the following two relations, and :

    R A B 10 20 20 30 30 40 30 50 50 95 S A C 10 90 30 45 40 80
    The total number of tuples obtained by evaluating the following expression 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 to find all matching (A, B, C) tuples. Second, apply the selection to filter the joined result.

    Learning route:

    Step 1: Perform the join . We match rows where .

    • matches Joined tuple: .
    • has no match in .
    • matches Joined tuple: .
    • matches Joined tuple: .
    • has no match in .

    Step 2: The intermediate joined relation has 3 tuples: , , and .

    Step 3: Apply the selection .

    • For : is True. (Keep)
    • For : is True. (Keep)
    • For : is False. (Discard)

    Step 4: Count the remaining tuples. There are exactly 2 tuples.

    Final Answer: 2.

    Question 7 · Databases · 2022 NAT
    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
    sNosNamedNo
    S01JamesD01
    S02RockyD01
    S03JacksonD02
    S04JaneD01
    S05MilliD02

    Dept
    dNodName
    D01CSE
    D02EEE

    Course
    cNocNamedNo
    C11DSD01
    C12OSD01
    C21DED02
    C22PTD02
    C23CVD03

    Register
    sNocNo
    S01C11
    S01C12
    S02C11
    S03C21
    S03C22
    S03C23
    S04C11
    S04C12
    S05C11
    S05C21


    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)
    • S03: Registered for C21, C22, C23. EXCEPT yields {C11, C12}. (Discard)
    • S04: Registered for C11, C12. EXCEPT is empty. (Keep)
    • S05: Registered for C11, C21. EXCEPT yields {C12}. (Discard)

    Step 5: The students kept are S01 and S04. Total rows returned = 2.

    Final Answer: 2.

    Question 8 · Databases · 2022 MSQ
    Consider the following three relations in a relational database.



    Which of the following relational algebra expressions return the set of who own all the brands?
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    ["A","B"]

    Step-by-Step Solution

    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 who own every present in the relation. This is exactly .

    Step 2: Option A is the direct division expression: . This is syntactically and logically correct.

    Step 3: Option B is the standard expansion of division using basic operators: Candidates Failures.

    • Candidates: (all employees who own at least one brand).
    • All possible pairs: .
    • Missing pairs: (All possible pairs) .
    • Failures (employees with missing pairs): (Missing pairs).
    • Result: Candidates Failures. This matches Option B exactly.

    Step 4: Option C divides by , which only contains brands that are actually owned by someone. If a brand exists in 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 and , which generates spurious pairs not present in the actual relation, corrupting the division logic.

    Final Answer: Options A and B are correct.

    Question 9 · Databases · 2021_Set2 MCQ
    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
    1. A.

      employees in the department.

    2. B.

      employees in the company.

    3. C.

      female employees in the department.

    4. 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_Set1 MCQ
    The following relation records the age of 500 employees of a company, where empNo (indicating the employee number) is the key:


    Consider the following relational algebra expression:


    What does the above expression generate?
    1. A.

      Employee numbers of only those employees whose age is the maximum.

    2. B.

      Employee numbers of only those employees whose age is more than the age of exactly one other employee.

    3. C.

      Employee numbers of all employees whose age is not the minimum.

    4. 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 pairs every employee with every other employee who has a strictly smaller age.

    Step 3: The projection 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.

    Final Answer: Option C.

    More previous year questions (pyqs) in this unit