I know this is old stuff, but still it is worth to mention.
This issue may cause problems(if you rely on the order results)
when you upgrade SQL Server 2000 to 2005 or 2008.
You cannot create a view/subquery with "order by"
clause without specifying TOP or FOR XML clause.
If you think for a moment there is really no sence to
use "Order By" in a derived table/subquery or View unless
the TOP clause defines what data to return.
The "Order By" clause in the definition of a view, inline function,
derived table or subquery is used only to determine the rows
returned by the TOP clause.
For instance, to determine the TOP 5 records that occur
in a certain order.The "Order By" clause DOES NOT
control the order of those 5 records when they are
returned outside the view.So, to control the order of the
records that are returned by the view, you need to use
ORDER BY in your SELECT * FROM VIEW statement.
Let`s see an example,I will create a table,populate it
with 3 rows.Then create a view on the table with "order by"
with Descending order.
Finally I will try to select from the View.
CREATE TABLE TestTable
RowID INT NOT NULL,
SomeName VARCHAR(20) NOT NULL
INSERT INTO TestTable (RowID,SomeName)
CREATE VIEW vw_Test
SELECT TOP 100 PERCENT RowID,SomeName
ORDER BY RowID DESC
SELECT * FROM vw_Test;
-- The results of the select:
As you can see the results are NOT ordered in descending
order by the RowID column.
The correct way to do it is to use an ORDER BY on the
outermost query block.
SELECT * FROM vw_Test ORDER BY RowID DESC;
PS: In SQL Server 2000 the result set of the
SELECT * FROM vw_Test
will be ordered in descending order.
Check this good article about the issue: