Does “group by” automatically guarantee “order by”?

后端 未结 6 1016
予麋鹿
予麋鹿 2021-02-12 16:51

Does \"group by\" clause automatically guarantee that the results will be ordered by that key? In other words, is it enough to write:

select * 
from table
group          


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-12 17:20

    It depends on the database vendor.

    For example PostgreSQL does not automatically sort the grouped result. Here you have to use order by to get the data sorted.

    But Sybase and Microsoft SQL Server do. Here you can use order by to change the default sorting.

提交回复
热议问题