Regarding SQL Server, you can't add ORDER BY in the statement of the view.

xiaoxiao2021-03-06  113

I wrote a SQL statement today.

SELECT * FROM

SELECT ... from a? union? Select ... from b Order by B.xx

AS TMP

SQL query analyzer is always an error: The Order by Clause Is Invalid in Views, Inline functions, Derived Tables, And Subqueries, Unless Top is Also Specified.

Yes, you can perform the SELECT ... from a? Union? Select ... from b Order by B.xx statement.

Later, the reasons were as follows:

Constructing the view in SQL cannot use the Order By word, namely:

???? If the query completion of view create view v_test as select * from sysobjects order by name will prompt an error: The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.

In nested queries, the system will automatically be select ... from a? Union? Select ... from b Order by B.xx statement, there is a view, of course, it will report an error, remove the Order By After that, it is successful!

转载请注明原文地址:https://www.9cbs.com/read-126608.html

New Post(0)