How to get an ordered presentation?

My "VIEW" is streamlined. But when I use select to display its result, the output is shuffled. This also happens with the following statement

SELECT * FROM (SELECT * FROM TABLE ORDER BY COLUMNA) AS DERIVEDTABLE

How to prevent this shuffling?

+3
source share
3 answers

you should only have ORDER BYan external choice that uses the view:

SELECT * FROM (SELECT * FROM TABLE) AS DERIVEDTABLE ORDER BY YourColumn

if you do not use TOP

SELECT * FROM (SELECT top 1000000 * FROM TABLE ORDER BY COLUMNA) AS DERIVEDTABLE

however, the final sort order may still change depending on the external request, unless you add another order:

SELECT * FROM (SELECT top 1000000 * FROM TABLE ORDER BY COLUMNA) AS DERIVEDTABLE
ORDER BY COLUMNA
+2
source

Unfortunately, views cannot be ordered in SQL Server. You must do this in the select statement that reads the view.

, .

+3

. - - , ORDER BY . ORDER BY (, , "TOP 10" TOP).

SQL Server 2000 , ORDER BY , , , Enterprise Manager SSMS , . . , , -, .

+1

Source: https://habr.com/ru/post/1774123/


All Articles