in Databases edited by
11,494 views
40 votes
40 votes

Consider the following relation

Cinema($\textit{theater, address, capacity}$)

Which of the following options will be needed at the end of the SQL query

SELECT P1.address
FROM Cinema P1

such that it always finds the addresses of theaters with maximum capacity?

  1. WHERE P1.capacity >= All (select P2.capacity from Cinema P2)
  2. WHERE P1.capacity >= Any (select P2.capacity from Cinema P2)
  3. WHERE P1.capacity > All (select max(P2.capacity) from Cinema P2)
  4. WHERE P1.capacity > Any (select max(P2.capacity) from Cinema P2)
in Databases edited by
11.5k views

4 Comments

I was also confused in C,D now it is clear why they are not the right choice
0
0
(b) → ‘Any’ means that if there is atleast one theater whose capacity is less than that of P1.capacity, then P1.capacity will return. Possibility of other theaters having capacity > P1.capacity still exists. To cover this, ‘All’ is needed. Hence (a)
0
0

P1 and P2 are just two instances of same table, i.e both P1 and P2 will have same entries.

0
0

3 Answers

73 votes
73 votes
Best answer
A is the answer

B - Returns the addresses of all theaters.
C - Returns null set. max() returns a single value and there won't be any value > max.
D - Returns null set. Same reason as C. All and ANY works the same here as max returns a single value.
edited by
by

4 Comments

@krati liotriya

In option A condition  is.     >= all

And  with >all  output is null but  with = all  output should be all  selected capacities by inner query . So  every capacity wheather it is maximum or not,  is going to be selected.

you are getting it wrong. in option a) ( select p2. capacity from cinema P2) this inner query will give the table of all theaters with their capacity .now when it applies on outer query >=all outer query will select only those theaters from P1 (outer table) whose capacity is greater than all of the theaters​​​​​​​ of P2 table.

 

0
0
This simple example absolutely cleared ma doubt!!!;)
0
0
WHERE P1.capacity > All (select P2.capacity from Cinema P2)
 Here '>' use so, null set return..

WHERE P1.capacity >= All (select P2.capacity from Cinema P2)

Here, '>=' use means it will return the "max" because all capacity less than the max capacity in the table. only the max value from the instance P2 is >= max value in the instance p1.

0
0
6 votes
6 votes
Answer is A.

Inner query collects capacities of all the theatres and in outer query we are filtering the tuples with the condition  " p1.capacity>=All". So the theatre which is having maximum capacity will be satisfy the condition.
2 votes
2 votes

(A) : Inner query collects capacities of all the theatres and in outer query we are filtering the tuples 
with the condition “capacity>=All”. So the theatres which are having maximum capacity will 
be satisfy the conductivity and they will.

(B) : Returns all the rows as ANY is used

(C)  & (D): Returns no rows as nothing can be greater than all or any of the maximum values

3 Comments

thanks heena singh Junior
0
0
Anyone please explain how to work all , any function with example
0
0
What if in option (C) it is >= ALL ?
0
0
Answer:

Related questions