I tried to work around this objection by only omitting the ORDER BY clause if either: 1. The outer query is not an aggregate 2. The outer query is an aggregate but it only uses the built-in count(), min(), or max() functions. And yet there are still issues. See the [ef97c3e7c3ea2cf1](src:/info/ef97c3e7c3ea2cf1) check-in for the code so far.