Consider the following relation
Cinema()
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?
View worked solution
Answer: A
To find the addresses of theaters with the maximum capacity, we need to select those tuples where the capacity is greater than or equal to every capacity present in the Cinema relation.
Let us analyze each option:
- Option A:
WHERE P1.capacity >= ALL (SELECT P2.capacity FROM Cinema P2)
The subquery(SELECT P2.capacity FROM Cinema P2)returns the set of all capacities in the relation. The conditionP1.capacity >= ALL (...)evaluates to true only ifP1.capacityis greater than or equal to every element in this set. This is the definition of the maximum value. Thus, this option correctly finds the theaters with the maximum capacity. - Option B:
WHERE P1.capacity >= ANY (SELECT P2.capacity FROM Cinema P2)
The condition>= ANYevaluates to true ifP1.capacityis greater than or equal to at least one capacity in the database. This will select almost all theaters (except those with capacity strictly less than the minimum, which is impossible since every capacity is itself). - Option C:
WHERE P1.capacity > ALL (SELECT MAX(P2.capacity) FROM Cinema P2)
The subquery returns a single value: the maximum capacity . The condition simplifies toP1.capacity > M. Since no capacity can be strictly greater than the maximum capacity , this query will always return an empty result. - Option D:
WHERE P1.capacity > ANY (SELECT MAX(P2.capacity) FROM Cinema P2)
Similar to Option C, this simplifies toP1.capacity > M, which also yields an empty result.
Therefore, Option A is the correct choice.
Free practice · Your answers on this page are not saved.
