WITH RECURSIVE CTE AS
(SELECT MIN(period_start) as date
FROM Sales
UNION ALL
SELECT DATE_ADD(date, INTERVAL 1 day)
FROM CTE
WHERE date <= ALL (SELECT MAX(period_end) FROM Sales))
What is the difference of using ALL in the where clause and not using ALL?
I have tried both, all returns the same result.
2
Answers
The
ALL
function means the comparison must be true for all values returned by the subquery. But the subquery returns only one value, because you used the aggregate function MAX() with no GROUP BY clause.Using ALL in this specific example makes no difference. It does no harm, but it is superfluous.
ANY
andALL
operators are used withWHERE
orHAVING
.ANY
andALL
operate on subqueries that return multiple values.ANY
returns true if any of the subquery values meet the condition.ALL
returns true if all of the subquery values meet the condition.Example: