Database table by name Loan_Records is given below. Borrower Bank_Manager…

2011

Database table by name Loan_Records is given below.

Borrower

Bank_Manager

Loan_Amount

Ramesh

Sunderajan

10000.00

Suresh

Ramgopal

5000.00

Mahesh

Sunderajan

7000.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 );

  1. A.

    3

  2. B.

    9

  3. C.

    5

  4. D.

    6

Attempted by 148 students.

Show answer & explanation

Correct answer: C

Correct result: 5.

Explanation: The two subqueries both include the column Bank_Manager, so NATURAL JOIN matches rows on Bank_Manager. Each matching pair becomes a row in the join result.

  • Bank_Manager = Sunderajan: appears twice in the first subquery (Borrower = Ramesh, Mahesh) and twice in the second subquery (Loan_Amount = 10000.00, 7000.00), so 2 × 2 = 4 joined rows.

  • Bank_Manager = Ramgopal: appears once in each subquery (Suresh and 5000.00), so 1 × 1 = 1 joined row.

  • Total rows after the NATURAL JOIN = 4 + 1 = 5, so SELECT count(*) returns 5.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir