I am experiencing some strange behaviour and I really don’t have test date/ environments, so
Will this query return top 5 rows ordered by count, or will it take top 5 rows and sort them then. What would be the query for the first?
select top 5 l.userId, count(*) "count" from Log l
where ...
group by l.userId
order by "count" desc
It couldn’t possibly have taken more than a few minutes to create some test data, but yes, that query does what you want it to do.
TOPdoes its job afterORDER.