The Gateway to Computer Science Excellence

+25 votes

Consider the following relations $A, B$ and $C:$

$$\overset{\textbf{A}}{\begin{array}{|c|c|c|}\hline\\

\textbf{Id}& \textbf{Name}& \textbf{Age} \\\hline

12& \text{Arun}& 60 \\ \hline

15& \text{Shreya}& 24 \\ \hline

99& \text{Rohit}& 11 \\\hline

\end{array}}\qquad \overset{\textbf{B}}{\begin{array}{|c|c|c|}\hline\\

\textbf{Id}& \textbf{Name}& \textbf{Age} \\\hline

15& \text{Shreya}& 24 \\ \hline 25 & \text{Hari} & 40 \\ \hline 98 & \text{Rohit} & 20 \\ \hline

99& \text{Rohit}& 11 \\\hline

\end{array}}\qquad \overset{\textbf{C}}{\begin{array}{|c|c|c|}\hline\\

\textbf{Id}& \textbf{Phone}& \textbf{Area} \\\hline

10& 2200& 02 \\ \hline

99& 2100& 01\\ \hline

\end{array}}$$

How many tuples does the result of the following SQL query contain?

SELECT A.Id FROM A WHERE A.Age > ALL (SELECT B.Age FROM B WHERE B.Name = ‘Arun’)

- $4$
- $3$
- $0$
- $1$

+33 votes

Best answer

<cond> ALL evaluates to TRUE if inner query returns no tuples. So, Number of tuples returned will be number of tuples in $A = 3$.

Reference: http://dcx.sap.com/1200/en/dbusage/all-test-quantified-subquery.html

Correct Answer: $B$

+3

Will this hold even for "... >any( /*empty collection*/ )...." or "... >some( /*empty collection*/ )...." also?

0

In case of any, when subquery returns empty set, then outer query will return nothing. Same link which Arjun Sir has mentioned.

http://dcx.sap.com/1200/en/dbusage/quantified-comparison-test-how-subquery.html

http://dcx.sap.com/1200/en/dbusage/quantified-comparison-test-how-subquery.html

+13 votes

Ans 3 tuple

All condition with empty return true

Also the result of subquery is empty So all id of A will be selected.

All condition with empty return true

Also the result of subquery is empty So all id of A will be selected.

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.5k
- Others 1.5k
- Admissions 595
- Exam Queries 576
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 17

50,647 questions

56,508 answers

195,530 comments

100,967 users