Is order by clause allowed in a subquery

前端 未结 9 1502
离开以前
离开以前 2020-12-10 14:34

Is there any reason why or why not you should do an \'order by\' in a subquery?

相关标签:
9条回答
  • 2020-12-10 15:26

    Unless you use top it is not useful since you will be ordering in the outer query anyway

    0 讨论(0)
  • 2020-12-10 15:28

    No ORDER BY is valid in a subquery when you are interested in a subset of the overall data, hence you always need a TOP (SQL Server). There's no point having an ORDER BY without TOP in a subquery because the overall ordering of the results is handled by the outer query.

    0 讨论(0)
  • 2020-12-10 15:34

    Depending on the size of the sub-query, it will impact performance to a varrying degree.

    Order shouldn't matter on a sub-query though. You should be able to move the Order By portion to the Outer Query (which should be the one returning the final results).

    0 讨论(0)
提交回复
热议问题