Question

Database table by name Loan_Records is given below.

BorrowerBank_ManagerLoan_Amount
RameshSunderajan10000.00
SureshRamgopal5000.00
MaheshSunderajan7000.00

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
Official answer and solution
Official answer
C
From
Official GATE 2011 answer key

Solution

Trace the projections and natural join on the common attribute Bank_Manager.

  1. Projection S=ΠBorrower,Bank_Manager(Loan_Records)S = \Pi_{\text{Borrower}, \text{Bank\_Manager}}(\text{Loan\_Records}) contains:
  • (Ramesh, Sunderajan)
  • (Suresh, Ramgopal)
  • (Mahesh, Sunderajan)
  1. Projection T=ΠBank_Manager,Loan_Amount(Loan_Records)T = \Pi_{\text{Bank\_Manager}, \text{Loan\_Amount}}(\text{Loan\_Records}) contains:
  • (Sunderajan, 10000.00)
  • (Ramgopal, 5000.00)
  • (Sunderajan, 7000.00)
  1. Natural join S⋈TS \bowtie T equates the common attribute Bank_Manager:
  • For Bank_Manager = Sunderajan: 2 records in SS join with 2 records in TT, yielding 2×2=42 \times 2 = 4 joined tuples.
  • For Bank_Manager = Ramgopal: 1 record in SS joins with 1 record in TT, yielding 1×1=11 \times 1 = 1 joined tuple.
  1. Total tuples in the natural join = 4+1=54 + 1 = 5.
Final answer

C

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2011 Computer Science and Information Technology (CS)
Question
46 of 65, printed as CS Q.46
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.