Consider the following SQL query: SELECT DISTINCT T.branch_name FROM branch AS…
2011
Consider the following SQL query:
SELECT DISTINCT T.branch_name
FROM branch AS T, branch AS S
WHERE T.assets > S.assets
AND S.branch_city = 'DELHI';What does the query return?
Answer: A. All branches whose assets exceed the assets of at least one branch located in Delhi. — ConceptA comma-separated FROM clause forms candidate pairs of rows. A WHERE condition retains a pair only when all its predicates are true. If a projected row…
- A.
All branches whose assets exceed the assets of at least one branch located in Delhi.
- B.
All branches whose assets exceed the assets of every branch located in Delhi.
- C.
The Delhi branch with the greatest assets.
- D.
All Delhi branches whose assets exceed the assets of at least one branch outside Delhi.
Attempted by 28 students.
Show answer & explanation
Correct answer: A
Concept
A comma-separated FROM clause forms candidate pairs of rows. A WHERE condition retains a pair only when all its predicates are true.
If a projected row has at least one qualifying partner, it appears in the result; DISTINCT then removes duplicate projected values.
Application
TandSare two aliases of the samebranchtable, so the query considers pairs consisting of a candidate branchTand a comparison branchS.The predicate
S.branch_city = 'DELHI'limitsSto branches located in Delhi.For a fixed
Trow, the conditionT.assets > S.assetsis satisfied when there exists at least one Delhi branchSwith fewer assets.The
SELECTclause projectsT.branch_name, andDISTINCTkeeps each qualifying branch name only once even if several Delhi rows satisfy the comparison.
Cross-check and contrast
The phrase “every Delhi branch” would require a universal comparison such as
> ALLor a comparison with the maximum Delhi assets.Selecting the richest Delhi branch would require restricting
Tto Delhi and applying a maximum or ordering rule.Comparing Delhi branches with outside-Delhi branches would require explicit city predicates on both aliases.
Therefore, the query returns all branches whose assets exceed the assets of at least one branch located in Delhi.