May 22, 2013
SQLite's HAVING clause picks an arbitrary row
Most SQL engines don't allow non-aggregate expressions in the HAVING
clause. For instance, the Postgres docs state:
Each column referenced in
condition
must unambiguously reference a grouping column
SQLite, on the other hand, takes a surprising approach:
If a HAVING clause is a non-aggregate expression, it is evaluated with respect to an arbitrarily selected row from the group.
Perhaps this approach has precedence in other SQL implementations, but I would much prefer a hard fail over an arbitrary result.