Can I depend on order of output when using row_number()

后端 未结 4 1222
孤独总比滥情好
孤独总比滥情好 2021-01-21 09:09

I believe the answer is no. And am looking for a counter example to show that order of output is not guaranteed, absent an order by clause.

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-21 09:22

    If you want it ordered, you must use ORDER BY.

    just look at the execution plan with

    SET SHOWPLAN_ALL ON
    

    if there is no "order by" in the StmtText column, you just get things however they are sorted after all the work is done. Sometimes you get lucky, sometime not, with how the data is stored/loaded/filtered/joined, etc. and how it is returned.

提交回复
热议问题