Database table by name is given below.
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
);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
The subquery selects the columns Borrower and Bank_Manager from the Loan_Records table:
Step 2: Analyze Subquery
The subquery selects the columns Bank_Manager and Loan_Amount from the Loan_Records table:
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 and where the Bank_Manager values are identical:
- For
Bank_Manager = Sunderajan:- Tuples in :
(Ramesh, Sunderajan),(Mahesh, Sunderajan)(2 tuples) - Tuples in :
(Sunderajan, 10000.00),(Sunderajan, 7000.00)(2 tuples) - Joining these yields tuples:
(Ramesh, Sunderajan, 10000.00)(Ramesh, Sunderajan, 7000.00)(Mahesh, Sunderajan, 10000.00)(Mahesh, Sunderajan, 7000.00)
- Tuples in :
- For
Bank_Manager = Ramgopal:- Tuples in :
(Suresh, Ramgopal)(1 tuple) - Tuples in :
(Ramgopal, 5000.00)(1 tuple) - Joining these yields tuple:
(Suresh, Ramgopal, 5000.00)
- Tuples in :
Step 4: Count the Tuples
The total number of tuples in the resulting relation is .
Thus, the query SELECT count(*) returns 5.
Free practice · Your answers on this page are not saved.
