SQLite syntax for "ALL" SQLite syntax for "ALL" sqlite sqlite

SQLite syntax for "ALL"


I doubt that there is an ALL() operator in SQLite. However, you can write something that is functionally equivalent using MAX() and MIN().

SELECT name FROM table WHERE number >= (SELECT MAX(another_number) FROM another_table WHERE ...)


SQLite does have an ALL keyword; but, it does not do what you want it to. (Fortunately, @lawrence's answer does.)

While the ALL keyword is not permitted as part of the WHERE expression, the keyword can appear a couple of other places.

From http://www.sqlite.org/lang_select.html:

SELECT ALL * ...

One of the ALL or DISTINCT keywords may follow the SELECT keyword in a simple SELECT statement. If the simple SELECT is a SELECT ALL, then the entire set of result rows are returned by the SELECT. If neither ALL or DISTINCT are present, then the behavior is as if ALL were specified.

SELECT ... UNION ALL SELECT ...

A compound SELECT created using UNION ALL operator returns all the rows from the SELECT to the left of the UNION ALL operator, and all the rows from the SELECT to the right of it. The UNION operator works the same way as UNION ALL, except that duplicate rows are removed from the final result set.


SQLite does not have an ALL operator. You might be tempted to write something like this:

select ... where number >= (select max(...) from ...);

However, this is not equivalent to the original query in all cases. If the subquery has no results, then number is greater than all of them (vacuously true). But the maximum of zero numbers is NULL, and number >= NULL is false (or rather, unknown in ternary logic, which gets treated as false in the end).

The following query is equivalent to the one using ALL, including for the empty result case:

select ... where not exists (select * from ... where number < X);