Avoid ordering when counting.

This not only optimizes the query, but also avoid errors caused when
ordering by fields set in the WHERE clause, because count() overrides
them by default.