GATE / CS ARCHIVE

GATE CSE 2011 / QUESTION 46

Counting a natural join on a shared manager

Database Management Systems · SQL & Queries · Full GATE CSE 2011 paper

GATE 2011, Q46 2 marks · MCQ
Report issue

SQL & Queries

Question 46, GATE 2011: Loan_Records has columns Borrower,Bank_Manager,Loan_Amount and rows (Ramesh,Sunderajan,10000.00), (Suresh,Ramgopal,5000.00), (Mahesh,Sunderajan,7000.00). Evaluate SELECT count(*) FROM ((SELECT Borrower,Bank_Manager FROM Loan_Records) AS S NATURAL JOIN (SELECT Bank_Manager,Loan_Amount FROM Loan_Records) AS T).

(A) 3
(B) 9
(C) 5
(D) 6
Tap to enlarge
Your answer
Answer & solution

Official answer: C

The common column of the two projections is Bank_Manager. Sunderajan appears in two rows of each projection, so the natural join yields 2×2=4 combinations for that manager. Ramgopal appears once in each projection, yielding 1×1=1 combination. COUNT(*) returns 4+1=5, option C. The join does not pair rows by their original borrower, since Borrower is absent from the second projection.

The projected left rows are (Ramesh,Sunderajan),(Suresh,Ramgopal),(Mahesh,Sunderajan). The right rows are (Sunderajan,10000),(Ramgopal,5000),(Sunderajan,7000). Each of Ramesh and Mahesh joins with both Sunderajan amounts, yielding four rows; Suresh joins with the single Ramgopal amount. COUNT(*) counts those joined rows, including combinations that were not in the original table. Joining projections can create extra combinations whenever their common attribute is not a key.

Original paper, page 12 · Answer key