chapter

    Relational Algebra and Sql Queries Pyqs for Gate Da

    Solve 9+ Relational Algebra and Sql Queries previous year questions for GATE DA 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 PYQ
    Level 3: Exam Standard
    Let Account be a relation as shown.

    Account
    AccNo Balance
    A1 5000
    A2 5000
    A3 10000
    A4 15000
    A5 18000

    Consider the given SQL query.

    SELECT AccNo FROM Account AS A
    WHERE (SELECT COUNT(*) FROM Account AS B
    WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)
    FROM Account AS C WHERE A.Balance > C.Balance)

    The number of rows returned by the SQL query is __________ . (Answer in integer)
    Question 2
    2026 PYQ
    Level 3: Exam Standard
    Let there be two relations and as shown. has three columns and . has two columns and .


         
    P1   Q1   R1
    P2   Q2   R2
    P3   Q3   R2


      
    P1   10
    P1   15
    P2   20
    P3   1

    Consider that the following tuple relational calculus expression is evaluated.



    The number of tuples that will be returned is __________ . (Answer in integer)
    Question 3
    2026 PYQ
    Level 3: Exam Standard
    Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the employee is a member. TeamID is a NOT NULL column.

    We want to display the size of the team (denoted as TeamSize) in which each employee is a member by using SQL. As an example, the desired output for the given Employee table is also shown in tabular form.

    Which of the following is/are correct?

    Employee
    EmpID TeamID
    1 8
    2 8
    3 8
    4 7
    5 7
    6 9

    Output
    EmpID TeamSize
    1 3
    2 3
    3 3
    4 2
    5 2
    6 1
    Question 4
    2026 PYQ
    Level 3: Exam Standard
    Consider the given relations and . The relation has three columns and . The relation has three columns and . The relation has two columns and .


         
    P1   Q1   R1
    P2   Q2   R2
    P3   Q3   R2


         
    P1   Q1   2
    P1   Q2   5
    P2   Q1   6
    P3   Q3   1


      
    P1   T1
    P3   T2
    P4   T3
    P4   NULL

    Consider the relational algebra expression



    where denotes natural join operation.

    Which of the following options is the correct output for the given expression?
    Question 5
    2025 PYQ
    Level 3: Exam Standard
    Consider the following tables, Loan and Borrower, of a bank.

    Loan
    loan_num branch_name amount
    L11 Banjara Hills 90000
    L14 Kondapur 50000
    L15 SR Nagar 40000
    L22 SR Nagar 25000
    L23 Balanagar 80000
    L25 Kondapur 70000
    L19 SR Nagar 65000

    Borrower
    customer_name loan_num
    Anand L11
    Karteek L11
    Karteek L14
    Ankita L15
    Gopal L19
    Karteek L22
    Karteek L23
    Sunil L23
    Sunil L25

    Query: \pi_{\text{branch_name}, \text{customer_name}}(\text{Loan} \bowtie \text{Borrower}) \div \pi_{\text{branch_name}}(\text{Loan})
    where denotes natural join.
    The number of tuples returned by the above relational algebra query is
    (Answer in integer)
    Question 6
    2025 PYQ
    Level 3: Exam Standard
    Consider the following three relations:

    Car (model, year, serial, color)
    Make (maker, model)
    Own (owner, serial)

    A tuple in Car represents a specific car of a given model, made in a given year, with a serial number and a color. A tuple in Make specifies that a maker company makes cars of a certain model. A tuple in Own specifies that an owner owns the car with a given serial number. Keys are underlined; (owner, serial) together form key for Own. ( denotes natural join)


    Which one of the following options describes what the above expression computes?
    Question 7
    2025 PYQ
    Level 3: Exam Standard
    On a relation named Loan of a bank:

    Loan
    loan number branch name amount
    L11 Banjara Hills 90000
    L14 Kondapur 50000
    L15 SR Nagar 40000
    L22 SR Nagar 25000
    L23 Balanagar 80000
    L25 Kondapur 70000
    L19 SR Nagar 65000

    the following SQL query is executed.

    SELECT L1.loan number
    FROM Loan L1
    WHERE L1.amount > (SELECT MAX (L2.amount)
                        FROM Loan L2
                        WHERE L2.branch name = ’SR Nagar’);

    The number of rows returned by the query is (Answer in integer)
    Question 8
    2024 PYQ
    Level 3: Exam Standard
    Consider the following two tables named Raider and Team in a relational database
    maintained by a Kabaddi league. The attribute ID in table Team references the
    primary key of the Raider table, ID.

    Raider
    IDNameRaidsRaidPoints
    1Arjun200250
    2Ankush190219
    3Sunil150200
    4Reza150190
    5Pratham175220
    6Gopal193215

    The SQL query described below is executed on this database:

    SELECT *
    FROM Raider, Team
    WHERE Raider.ID=Team.ID AND City=“Jaipur” AND
    RaidPoints > 200;

    The number of rows returned by this query is ______.

    Team
    CityIDBidPoints
    Jaipur2200
    Patna3195
    Hyderabad5175
    Jaipur1250
    Patna4200
    Jaipur6200
    Question 9
    2024 PYQ
    Level 3: Exam Standard
    Consider a database that includes the following relations:
    Defender(name, rating, side, goals)
    Forward(name, rating, assists, goals)
    Team(name, club, price)
    Which ONE of the following relational algebra expressions checks that every name
    occurring in Team appears in either Defender or Forward, where denotes the
    empty set?
    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 and Sql Queries PYQs for GATE DA

    Solve 9+ Relational Algebra and Sql Queries previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Relational Algebra and SQL Queries

    Your Learning Journey
    1

    Relational Algebra & Semantics

    Formal query language using mathematical operations. Highest weightage topic.

    2

    SQL Joins, Aggregation & Grouping

    Practical SQL implementation with table combinations and summary computations.

    3

    SQL Subqueries & Evaluation

    Nested queries and execution semantics. Understand internal processing.

    By the end of this chapter, you will:
    • Write queries in both relational algebra and SQL
    • Predict query results for any given database instance
    • Understand join semantics and aggregation behavior
    • Analyze nested queries and their execution order

    What is Relational Algebra?

    The Core Idea

    Relational algebra is a procedural query language that operates on relations (tables) to produce new relations.

    InputOne or two relations
    OutputA new relation (table)
    ProceduralSpecifies how to get the result
    ComposableOutput becomes next input

    The Six Fundamental Operations

    OperationSymbolPurpose
    SelectFilter rows
    ProjectFilter columns
    UnionCombine rows
    DifferenceRemove rows
    ProductAll combinations
    RenameRename attrs

    Relational Algebra and Sql Queries: Solved Questions with Step-by-Step Explanations (9 Problems)

    Question 1 · Database Management and Warehousing · 2026 NAT
    Let Account be a relation as shown.

    Account
    AccNo Balance
    A1 5000
    A2 5000
    A3 10000
    A4 15000
    A5 18000

    Consider the given SQL query.

    SELECT AccNo FROM Account AS A
    WHERE (SELECT COUNT(*) FROM Account AS B
    WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)
    FROM Account AS C WHERE A.Balance > C.Balance)

    The number of rows returned by the SQL query is __________ . (Answer in integer)
    Correct Answer:

    3.00

    Step-by-Step Solution

    Insight: This is the classic median/rank pattern using correlated subqueries to count strictly greater and strictly smaller elements.

    Exam route: For each balance, count the number of strictly greater and strictly smaller balances. Keep the row if greater >= smaller.

    Learning route:

    Step 1: Recognize the pattern. The query uses correlated subqueries to count elements greater than and smaller than the current row's value. This is a standard technique for finding medians or ranks.

    Step 2: Evaluate for A1 (Balance = 5000).

    • Count of B where 5000 < B.Balance: B can be A3(10000), A4(15000), A5(18000). Count = 3.
    • Count of C where 5000 > C.Balance: None. Count = 0.
    • Condition: 3 >= 0. TRUE.

    Step 3: Evaluate for A2 (Balance = 5000).

    • Same as A1. Count greater = 3, Count smaller = 0.
    • Condition: 3 >= 0. TRUE.

    Step 4: Evaluate for A3 (Balance = 10000).

    • Count of B where 10000 < B.Balance: A4(15000), A5(18000). Count = 2.
    • Count of C where 10000 > C.Balance: A1(5000), A2(5000). Count = 2.
    • Condition: 2 >= 2. TRUE.

    Step 5: Evaluate for A4 (Balance = 15000).

    • Count of B where 15000 < B.Balance: A5(18000). Count = 1.
    • Count of C where 15000 > C.Balance: A1(5000), A2(5000), A3(10000). Count = 3.
    • Condition: 1 >= 3. FALSE.

    Step 6: Evaluate for A5 (Balance = 18000).

    • Count of B where 18000 < B.Balance: None. Count = 0.
    • Count of C where 18000 > C.Balance: A1, A2, A3, A4. Count = 4.
    • Condition: 0 >= 4. FALSE.

    Step 7: Count the TRUE rows: A1, A2, A3. Total = 3.

    Verification: The condition greater >= smaller identifies the median or lower-middle elements. For 5 elements, the median is the 3rd element (10000), and the lower-middle includes the two 5000s. Total 3 rows.

    Question 2 · Database Management and Warehousing · 2026 NAT
    Let there be two relations and as shown. has three columns and . has two columns and .


         
    P1   Q1   R1
    P2   Q2   R2
    P3   Q3   R2


      
    P1   10
    P1   15
    P2   20
    P3   1

    Consider that the following tuple relational calculus expression is evaluated.



    The number of tuples that will be returned is __________ . (Answer in integer)
    Correct Answer:

    2.00

    Step-by-Step Solution

    Insight: The TRC expression filters tuples in X based on existential conditions. The first condition is trivially true; the second checks if the tuple's P value has a matching S > 1 in Y.

    Exam route: Evaluate the existential conditions for each tuple in X row by row.

    Learning route:

    Step 1: Understand the expression structure. We are selecting tuples from that satisfy two existential conditions.

    Step 2: Evaluate Condition 1: . Since is already in , we can just pick . This condition is always TRUE for any .

    Step 3: Evaluate Condition 2: . We need to find at least one row in with the same value as , and with .

    Step 4: Check . . In , rows with are and . Both have (10 > 1, 15 > 1). Condition 2 is TRUE. Tuple included.

    Step 5: Check . . In , the row with is . . Condition 2 is TRUE. Tuple included.

    Step 6: Check . . In , the row with is . $1$ is NOT . Condition 2 is FALSE. Tuple excluded.

    Step 7: Count the included tuples: (P1, Q1, R1) and (P2, Q2, R2). Total = 2.

    Verification: Plug the conditions back. P1 and P2 have matching S > 1 in Y. P3 does not. Count is 2.

    Question 3 · Database Management and Warehousing · 2026 MSQ
    Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the employee is a member. TeamID is a NOT NULL column.

    We want to display the size of the team (denoted as TeamSize) in which each employee is a member by using SQL. As an example, the desired output for the given Employee table is also shown in tabular form.

    Which of the following is/are correct?

    Employee
    EmpID TeamID
    1 8
    2 8
    3 8
    4 7
    5 7
    6 9

    Output
    EmpID TeamSize
    1 3
    2 3
    3 3
    4 2
    5 2
    6 1
    1. A. SELECT E.EmpID, B.TeamSize
      FROM Employee AS E, (SELECT TeamID, COUNT(TeamID) AS TeamSize FROM Employee GROUP BY TeamID) AS B
      WHERE E.TeamID = B.TeamID
    2. B. SELECT A.EmpID, COUNT(B.TeamID) AS TeamSize
      FROM Employee AS A, Employee AS B
      WHERE A.TeamID = B.TeamID AND A.EmpID = B.EmpID
      GROUP BY A.EmpID
    3. C. SELECT B.EmpID, B.TeamSize
      FROM (SELECT EmpID, COUNT(TeamID) AS TeamSize
      FROM Employee GROUP BY EmpID) AS B
    4. D. SELECT A.EmpID, B.TeamSize
      FROM Employee AS A, (SELECT COUNT(TeamID) AS TeamSize FROM Employee GROUP BY TeamID) AS B
      WHERE A.TeamID = B.TeamID
    Correct Answer:

    ["A"]

    Step-by-Step Solution

    Insight: To display an aggregate (team size) for each individual row without collapsing the output, we must compute the aggregate in a derived table or use a self-join that preserves individual IDs.

    Exam route: Evaluate each option's GROUP BY and JOIN conditions to see which correctly pairs each employee with their team's total count.

    Learning route:

    Step 1: Analyze Option A. The inner query groups by TeamID and counts the members, producing a derived table B with columns (TeamID, TeamSize). The outer query joins Employee E with B on TeamID. This correctly assigns the team size to each employee. This matches the desired output.

    Step 2: Analyze Option B. The self-join condition includes A.EmpID = B.EmpID. Since EmpID is the primary key, this restricts B to be exactly the same row as A. COUNT(B.TeamID) will always be 1 for every employee. This is incorrect.

    Step 3: Analyze Option C. The query groups by EmpID. Since EmpID is the primary key, each group contains exactly one row. COUNT(TeamID) will always be 1. This is incorrect.

    Step 4: Analyze Option D. The derived table B only selects COUNT(TeamID) AS TeamSize; it does not include TeamID in its SELECT list. The outer query's WHERE clause attempts to join on B.TeamID, which does not exist in the derived table. This will cause a SQL error. This is incorrect.

    Verification: Only Option A correctly computes the team sizes (3, 3, 3, 2, 2, 1) and joins them back to the individual employees.

    Question 4 · Database Management and Warehousing · 2026 MCQ
    Consider the given relations and . The relation has three columns and . The relation has three columns and . The relation has two columns and .


         
    P1   Q1   R1
    P2   Q2   R2
    P3   Q3   R2


         
    P1   Q1   2
    P1   Q2   5
    P2   Q1   6
    P3   Q3   1


      
    P1   T1
    P3   T2
    P4   T3
    P4   NULL

    Consider the relational algebra expression



    where denotes natural join operation.

    Which of the following options is the correct output for the given expression?
    1. A.

      Two rows (P1, R1, 2) and (P1, R1, 5)

    2. B.

      Three rows (P1, R1, 2), (P1, R1, 5) and (P2, R2, 6)

    3. C.

      One row (P1, R1, 2)

    4. D.

      Zero rows

    Correct Answer:

    D

    Step-by-Step Solution

    Insight: Evaluate each sub-expression independently, then join the two results on their common attributes (P, Q, S). The join yields zero rows because the surviving tuples have no matching keys.

    Exam route: Compute left side and right side of the outer join separately, then check for matching (P, Q, S) values.

    Learning route:

    Step 1: Compute (natural join on P, Q).

    X: (P1,Q1,R1), (P2,Q2,R2), (P3,Q3,R2)

    Y: (P1,Q1,2), (P1,Q2,5), (P2,Q1,6), (P3,Q3,1)

    Matches: (P1,Q1) → (P1,Q1,R1,2); (P3,Q3) → (P3,Q3,R2,1).

    Result: {(P1,Q1,R1,2), (P3,Q3,R2,1)}.

    Step 2: Apply .

    (P1,Q1,R1,2): Q=Q1 (F), R=R1 (F) → F.

    (P3,Q3,R2,1): Q=Q3 (T) → T.

    Left result: {(P3,Q3,R2,1)}.

    Step 3: Compute (natural join on P).

    Y: (P1,Q1,2), (P1,Q2,5), (P2,Q1,6), (P3,Q3,1)

    Z: (P1,T1), (P3,T2), (P4,T3), (P4,NULL)

    Matches: P1 → (P1,Q1,2,T1), (P1,Q2,5,T1); P3 → (P3,Q3,1,T2).

    Result: {(P1,Q1,2,T1), (P1,Q2,5,T1), (P3,Q3,1,T2)}.

    Step 4: Apply .

    S=2 > 1 → T; S=5 > 1 → T; S=1 > 1 → F.

    Right result: {(P1,Q1,2,T1), (P1,Q2,5,T1)}.

    Step 5: Join left and right on common attributes (P, Q, S).

    Left: (P3, Q3, R2, S=1).

    Right: (P1, Q1, S=2, T1), (P1, Q2, S=5, T1).

    No match on P (P3 vs P1), Q (Q3 vs Q1/Q2), or S (1 vs 2/5).

    Final result: Zero rows.

    Verification: The left side has P3, Q3, S=1. The right side has P1, Q1/Q2, S=2/5. No overlap on any common attribute.

    Question 5 · Database Management and Warehousing · 2025 NAT
    Consider the following tables, Loan and Borrower, of a bank.

    Loan
    loan_num branch_name amount
    L11 Banjara Hills 90000
    L14 Kondapur 50000
    L15 SR Nagar 40000
    L22 SR Nagar 25000
    L23 Balanagar 80000
    L25 Kondapur 70000
    L19 SR Nagar 65000

    Borrower
    customer_name loan_num
    Anand L11
    Karteek L11
    Karteek L14
    Ankita L15
    Gopal L19
    Karteek L22
    Karteek L23
    Sunil L23
    Sunil L25

    Query: \pi_{\text{branch_name}, \text{customer_name}}(\text{Loan} \bowtie \text{Borrower}) \div \pi_{\text{branch_name}}(\text{Loan})
    where denotes natural join.
    The number of tuples returned by the above relational algebra query is
    (Answer in integer)
    Correct Answer:

    1.00

    Step-by-Step Solution

    Insight: Relational division R ÷ S finds tuples in R that are associated with ALL tuples in S. Here, it finds customers who have borrowed from ALL branches.

    Exam route: Compute the join, project the relevant columns, and then find the customer associated with every branch.

    Learning route:

    Step 1: Understand the division operation. returns tuples from that match with every tuple in on the common attributes. The result schema is the attributes of minus the attributes of .

    Step 2: Compute the natural join Loan ⋈ Borrower on loan_num.

    • L11: (Banjara Hills, Anand), (Banjara Hills, Karteek)
    • L14: (Kondapur, Karteek)
    • L15: (SR Nagar, Ankita)
    • L19: (SR Nagar, Gopal)
    • L22: (SR Nagar, Karteek)
    • L23: (Balanagar, Karteek), (Balanagar, Sunil)
    • L25: (Kondapur, Sunil)

    Step 3: Project branch_name, customer_name.

    • (Banjara Hills, Anand)
    • (Banjara Hills, Karteek)
    • (Kondapur, Karteek)
    • (SR Nagar, Ankita)
    • (SR Nagar, Gopal)
    • (SR Nagar, Karteek)
    • (Balanagar, Karteek)
    • (Balanagar, Sunil)
    • (Kondapur, Sunil)

    Step 4: Compute the divisor \pi_{\text{branch_name}}(\text{Loan}). The branches are: {Banjara Hills, Kondapur, SR Nagar, Balanagar}. Total 4 branches.

    Step 5: Perform the division. We need customers who are associated with ALL 4 branches.

    • Anand: only Banjara Hills (1 branch). No.
    • Karteek: Banjara Hills, Kondapur, SR Nagar, Balanagar (4 branches). YES.
    • Ankita: only SR Nagar (1 branch). No.
    • Gopal: only SR Nagar (1 branch). No.
    • Sunil: Balanagar, Kondapur (2 branches). No.

    Step 6: Only Karteek satisfies the condition. The result has 1 tuple.

    Verification: Karteek has loans L11, L14, L22, L23, which map to all 4 branches. No other customer has all 4.

    Question 6 · Database Management and Warehousing · 2025 MCQ
    Consider the following three relations:

    Car (model, year, serial, color)
    Make (maker, model)
    Own (owner, serial)

    A tuple in Car represents a specific car of a given model, made in a given year, with a serial number and a color. A tuple in Make specifies that a maker company makes cars of a certain model. A tuple in Own specifies that an owner owns the car with a given serial number. Keys are underlined; (owner, serial) together form key for Own. ( denotes natural join)


    Which one of the following options describes what the above expression computes?
    1. A.

      All owners of a red car, a car made by ABC, or a red car made by ABC

    2. B.

      All owners of more than one car, where at least one car is red and made by ABC

    3. C.

      All owners of a red car made by ABC

    4. D.

      All red cars made by ABC

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: The expression nests joins and selections from inside out. Each operation restricts the data further, culminating in owners of cars that are both red and made by ABC.

    Exam route: Trace from the innermost selection outward, identifying what each step filters or joins.

    Learning route:

    Step 1: → models made by ABC.

    Step 2: → cars of those models (joined on model).

    Step 3: → red cars among those (further filtered).

    Step 4: → ownership records for those cars (joined on serial).

    Step 5: → owner names.

    Interpretation: The expression finds all owners who own a car that is both red and made by ABC.

    Why others fail:

    • Option A suggests a union (red OR ABC OR both), but the joins act as intersection (AND).
    • Option B adds a condition about "more than one car", which is not present.
    • Option D omits the Own join and owner projection, so it would return cars, not owners.

    Verification: If a car is red and made by ABC, and an owner owns it, that owner appears in the result. This matches option C.

    Question 7 · Database Management and Warehousing · 2025 NAT
    On a relation named Loan of a bank:

    Loan
    loan number branch name amount
    L11 Banjara Hills 90000
    L14 Kondapur 50000
    L15 SR Nagar 40000
    L22 SR Nagar 25000
    L23 Balanagar 80000
    L25 Kondapur 70000
    L19 SR Nagar 65000

    the following SQL query is executed.

    SELECT L1.loan number
    FROM Loan L1
    WHERE L1.amount > (SELECT MAX (L2.amount)
                        FROM Loan L2
                        WHERE L2.branch name = ’SR Nagar’);

    The number of rows returned by the query is (Answer in integer)
    Correct Answer:

    3.00

    Step-by-Step Solution

    Insight: The inner subquery is non-correlated (it does not reference L1), so it evaluates exactly once to a single scalar value.

    Exam route: Compute MAX(amount) for branch_name = 'SR Nagar' first, then count outer rows with amount strictly greater than that value.

    Learning route:

    Step 1: Identify the inner query. It selects MAX(L2.amount) FROM Loan L2 WHERE L2.branch_name = 'SR Nagar'. Since L2 does not reference L1, this is a non-correlated subquery and runs once.

    Step 2: Filter Loan for branch_name = 'SR Nagar'. The matching rows are:

    • L15: 40000
    • L22: 25000
    • L19: 65000

    Step 3: MAX(40000, 25000, 65000) = 65000.

    Step 4: The outer query becomes: SELECT loan_number FROM Loan WHERE amount > 65000.

    Step 5: Check each row of Loan:

    • L11: 90000 > 65000 ✓
    • L14: 50000 > 65000 ✗
    • L15: 40000 > 65000 ✗
    • L22: 25000 > 65000 ✗
    • L23: 80000 > 65000 ✓
    • L25: 70000 > 65000 ✓
    • L19: 65000 > 65000 ✗ (strict inequality)

    Step 6: Count the TRUE rows: L11, L23, L25 → 3 rows.

    Verification: Plug 65000 back — only 90000, 80000, 70000 are strictly greater. Count is 3.

    Question 8 · Database Management and Warehousing · 2024 NAT
    Consider the following two tables named Raider and Team in a relational database
    maintained by a Kabaddi league. The attribute ID in table Team references the
    primary key of the Raider table, ID.

    Raider
    IDNameRaidsRaidPoints
    1Arjun200250
    2Ankush190219
    3Sunil150200
    4Reza150190
    5Pratham175220
    6Gopal193215

    The SQL query described below is executed on this database:

    SELECT *
    FROM Raider, Team
    WHERE Raider.ID=Team.ID AND City=“Jaipur” AND
    RaidPoints > 200;

    The number of rows returned by this query is ______.

    Team
    CityIDBidPoints
    Jaipur2200
    Patna3195
    Hyderabad5175
    Jaipur1250
    Patna4200
    Jaipur6200
    Correct Answer:

    3.00

    Step-by-Step Solution

    Insight: The query performs an implicit inner join on ID, then filters by City and RaidPoints. Count the rows that satisfy both conditions.

    Exam route: Join the tables on ID, then apply the WHERE conditions row by row.

    Learning route:

    Step 1: Join Raider and Team on ID.

    ID=1: (Arjun, 250) ⋈ (Jaipur, 1, 250) → RaidPoints=250, City=Jaipur

    ID=2: (Ankush, 219) ⋈ (Jaipur, 2, 200) → RaidPoints=219, City=Jaipur

    ID=3: (Sunil, 200) ⋈ (Patna, 3, 195) → RaidPoints=200, City=Patna

    ID=4: (Reza, 190) ⋈ (Patna, 4, 200) → RaidPoints=190, City=Patna

    ID=5: (Pratham, 220) ⋈ (Hyderabad, 5, 175) → RaidPoints=220, City=Hyderabad

    ID=6: (Gopal, 215) ⋈ (Jaipur, 6, 200) → RaidPoints=215, City=Jaipur

    Step 2: Apply WHERE City="Jaipur" AND RaidPoints > 200.

    ID=1: Jaipur, 250 > 200 → TRUE

    ID=2: Jaipur, 219 > 200 → TRUE

    ID=3: Patna → FALSE

    ID=4: Patna → FALSE

    ID=5: Hyderabad → FALSE

    ID=6: Jaipur, 215 > 200 → TRUE

    Step 3: Count TRUE rows: ID=1, 2, 6 → 3 rows.

    Verification: Check each Jaipur row: 250, 219, 215 are all > 200. Count is 3.

    Question 9 · Database Management and Warehousing · 2024 MCQ
    Consider a database that includes the following relations:
    Defender(name, rating, side, goals)
    Forward(name, rating, assists, goals)
    Team(name, club, price)
    Which ONE of the following relational algebra expressions checks that every name
    occurring in Team appears in either Defender or Forward, where denotes the
    empty set?
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: "Every name in Team appears in Defender or Forward" is a subset statement: .

    Exam route: Rewrite subset as set difference equals empty set: .

    Learning route:

    Step 1: Let , , .

    Step 2: The English condition is: every element of is in or in . That is .

    Step 3: The standard relational algebra test for is .

    Step 4: Substitute: .

    Step 5: This matches option C exactly.

    Why others fail:

    • Option A uses instead of , which would mean every team name is in both D and F.
    • Option B tests , the reverse direction with intersection.
    • Option D tests , the reverse direction.

    Verification: If T = {a, b}, D = {a, b, c}, F = {b, d}, then D ∪ F = {a, b, c, d}, T \ (D ∪ F) = ∅. Correct.

    More previous year questions (pyqs) in this unit