Skip to content
Official PYQ · 2011

GATE CS 2011 Q46 — Tuple Calculus and SQL

Explain with AI

Database table by name Loan_Records\text{Loan\_Records} is given below.
BorrowerBank_ManagerLoan_AmountRamesh Sunderajan10000.00SureshRamgopal5000.00MaheshSunderajan7000.00\begin{array}{|c|c|c|} \hline \textbf{Borrower} & \textbf{Bank\_Manager} &\textbf{Loan\_Amount} \\ \hline \text{Ramesh }& \text{Sunderajan} & 10000.00 \\ \hline \text{Suresh} & \text{Ramgopal} & 5000.00 \\ \hline \text{Mahesh} & \text{Sunderajan} & 7000.00\\ \hline \end{array}
What is the output of the following SQL query?

SELECT count(*)
FROM (
    SELECT Borrower, Bank_Manager FROM Loan_Records) AS S 
    NATURAL JOIN
    (SELECT Bank_Manager, Loan_Amount FROM Loan_Records) AS T
);
Choose one option
View worked solution

Answer: C

To find the output of the SQL query, let us break down the subqueries and trace the NATURAL JOIN operation step-by-step.

Step 1: Analyze Subquery SS

The subquery SS selects the columns Borrower and Bank_Manager from the Loan_Records table:

S=BorrowerBank_ManagerRameshSunderajanSureshRamgopalMaheshSunderajanS = \begin{array}{|c|c|} \hline \textbf{Borrower} & \textbf{Bank\_Manager} \\ \hline \text{Ramesh} & \text{Sunderajan} \\ \text{Suresh} & \text{Ramgopal} \\ \text{Mahesh} & \text{Sunderajan} \\ \hline \end{array}

Step 2: Analyze Subquery TT

The subquery TT selects the columns Bank_Manager and Loan_Amount from the Loan_Records table:

T=Bank_ManagerLoan_AmountSunderajan10000.00Ramgopal5000.00Sunderajan7000.00T = \begin{array}{|c|c|} \hline \textbf{Bank\_Manager} & \textbf{Loan\_Amount} \\ \hline \text{Sunderajan} & 10000.00 \\ \text{Ramgopal} & 5000.00 \\ \text{Sunderajan} & 7000.00 \\ \hline \end{array}

Step 3: Perform the NATURAL JOIN

A NATURAL JOIN joins the two relations on their common attribute, which is Bank_Manager. We match rows from SS and TT where the Bank_Manager values are identical:

  • For Bank_Manager = Sunderajan:
    • Tuples in SS: (Ramesh, Sunderajan), (Mahesh, Sunderajan) (2 tuples)
    • Tuples in TT: (Sunderajan, 10000.00), (Sunderajan, 7000.00) (2 tuples)
    • Joining these yields 2×2=42 \times 2 = 4 tuples:
      1. (Ramesh, Sunderajan, 10000.00)
      2. (Ramesh, Sunderajan, 7000.00)
      3. (Mahesh, Sunderajan, 10000.00)
      4. (Mahesh, Sunderajan, 7000.00)
  • For Bank_Manager = Ramgopal:
    • Tuples in SS: (Suresh, Ramgopal) (1 tuple)
    • Tuples in TT: (Ramgopal, 5000.00) (1 tuple)
    • Joining these yields 1×1=11 \times 1 = 1 tuple:
      1. (Suresh, Ramgopal, 5000.00)

Step 4: Count the Tuples

The total number of tuples in the resulting relation is 4+1=54 + 1 = 5.

Thus, the query SELECT count(*) returns 5.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions