LISTING 2-6
Query Demonstrating TOP with Unique ORDER BY List
SELECT TOP (5) orderid, orderdate, custid, empid
FROM Sales.Orders
ORDER BY orderdate DESC, orderid DESC;
This query returns the following output.
orderid orderdate custid empid
----------- ----------------------------- ----------- -----------
11077 2008-05-06 00:00:00.000 65 1
11076 2008-05-06 00:00:00.000 9 4
11075 2008-05-06 00:00:00.000 68 8
11074 2008-05-06 00:00:00.000 73 7
11073 2008-05-05 00:00:00.000 58 2
(5 row(s) affected)
If you examine the results of the queries from Listing 2-5 and Listing 2-6, you’ll notice that they
seem to be the same. The important difference is that the result shown in the query output for Listing
2-5 is one of several possible valid results for this query, whereas the result shown in the query output
for Listing 2-6 is the only possible valid result.
www.it-ebooks.info
Do'stlaringiz bilan baham: |