ALL SELECT MAX" vs "WHERE X> SELECT MAX" I stumbled upon a few queries that use the entire quantifier to maximize the subquery: Is the...">

"WHERE X> ALL SELECT MAX" vs "WHERE X> SELECT MAX"

I stumbled upon a few queries that use the entire quantifier to maximize the subquery:

Is there a difference between

SELECT name FROM bbc WHERE population > ALL (SELECT MAX(population) FROM bbc WHERE region = 'Europe') AND region = 'South Asia' 

and

 SELECT name FROM bbc WHERE population > (SELECT MAX(population) FROM bbc WHERE region = 'Europe') AND region = 'South Asia' 

?

+5
source share
1 answer

SELECT MAX is an aggregate operation, and so your subquery will select one row.

Applying ALL to a single line will have no effect.

If your subquery returned multiple rows, the non ALL version will result in an error. Also note that when using ALL you can remove MAX from the subquery and you will get the correct results (presumably with the same performance characteristics).

+4
source

Source: https://habr.com/ru/post/1207547/


All Articles