Skip to main content

GATE CSE 2011Databases › SQLVerified

GATE CSE 2011 PYQ: Database table by name Loan_Records \text{Loan\_Records} Loan_Records is given below. Borrower Bank_Manager…

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
);
  1. A
    3
  2. B
    9
  3. C
    5
    Correct answer
  4. D
    6

Answer

(C) 5 5 5

Approach

Compute the natural join on the common column $Bank_Manager$. For each bank manager value, every S-row with that manager joins with every T-row having the same manager, so the total count is the sum of squared frequencies of each $Bank_Manager$ value.

Natural join matches rows on $Bank_Manager$. The frequencies are Sunderajan: 2, Ramgopal: 1. Hence the join count is 2*2 + 1*1 = 5, matching option C.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.