The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+16 votes

Database table by name $\text{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(*)
    SELECT Borrower, Bank_Manager FROM Loan_Records) AS S 
    (SELECT Bank_Manager, Loan_Amount FROM Loan_Records) AS T
  1. 3
  2. 9
  3. 5
  4. 6
asked in Databases by Veteran (115k points)
edited by | 2k views

How the tables are joined in this , please somebody explain ?
@Arjun sir

1 Answer

+29 votes
Best answer

The answer is (c).

When we perform the natural join on $S$ and $T$ then result will be like this

Borrower Bank Manager Loan Amount
Ramesh Sunderajan $10,000.00$
Ramesh Sunderajan $7000.00$
Suresh Ramgopala $5000.00$
Mahesh Sunderajan $10,000.00$
Mahesh Sunderajan $7000.00$

After that count (*) will count total tuples present in this table  so here it is $5$

answered by Active (4.1k points)
edited by
No need of any doubt.
"The result of the natural join on R,S is the set of all combinations of tuples in R and S that are equal on their common attribute names"
Does the resulting table after natural join include the common attribute twice, or as a single column only ? I mean to say if S contains a,b and T contains a,c , then S NATURAL JOIN T will contain a,b,c or a,b,a,c ?
@learncp: just once as you can see in the output above
No sir I have some doubt in it.How this table comes after joining.Plz elaborate it

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
47,910 questions
52,287 answers
67,727 users