Why does SQL Server 2008 order when using a GROUP BY and no order has been specified?

后端 未结 4 722
无人共我
无人共我 2021-01-06 05:23

I\'m running into a very strange issue that I have found no explanation for yet. With SQL Server 2008 and using the GROUP BY it is ordering my columns without any ORDER BY s

4条回答
  •  情书的邮戳
    2021-01-06 06:16

    If you don't specify an order by clause, SQLServer is free to return the results in any order.

    Maybe in your specific query it will return results ordered, but that doesn't mean it will always sort resltsets when using a group by clause.

    Maybe (just maybe) it's doing some hash aggregate to compute the group by and the hash table happens to be sorted by 1,2,3,4. And then ir returning rows in the hash order...

提交回复
热议问题