What is the purpose of Order By 1 in SQL select statement?

后端 未结 8 1214
醉酒成梦
醉酒成梦 2020-12-12 19:43

I\'m reading through some old code at work, and have noticed that there are several views with an order by 1 clause. What does this accomplish?

Exampl

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 20:23

    As mentioned in other answers ORDER BY 1 orders by the first column.

    I came across another example of where you might use it though. We have certain queries which need to be ordered select the same column. You would get a SQL error if ordering by Name in the below.

    SELECT Name, Name FROM Segment ORDER BY 1
    

提交回复
热议问题