The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common ta

Posted Chuck Lu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common ta相关的知识,希望对你有一定的参考价值。

https://stackoverflow.com/questions/30045871/sorting-the-view-based-on-frequency-in-sql-server

Just like in sub queries, you can‘t use ORDER BY in a view definition in sql server unless you also use TOP.

The reason for this is that Views are acted upon as if they where tables, and tables in sql server (in fact, in any relational database) are considered as not ordered sets.
Just like there is no meaning to the order of records stored in a table, there is also no meaning to the order of records fetched by a view.
You can use a dirty hack and write SELECT TOP 100 PERCENT ... and then use ORDER BY, but I doubt if it has any meaning at all.

Having said all that, you can of course use ORDER BY in any query that selects from a view.

 
https://stackoverflow.com/questions/1622878/why-use-select-top-100-percent
select top 100 percent * from vie_trn_47 order by createdon desc

以上是关于The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common ta的主要内容,如果未能解决你的问题,请参考以下文章

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL

1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contai

解决[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL

linux下order by 报出ORDER BY clause is not in SELECT list

mysql Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nona

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated