May 2019
Intermediate to advanced
484 pages
11h 23m
English
The ORDER BY clause orders the results. The default order is ascending, meaning that the ASC keyword can be omitted. To produce the result set in descending order, DESC must be set explicitly. Building on the same example from the WHERE section, the following code block is used to explicitly present results in descending order of product name and location name:
SELECT P.Name AS ProductName, [PI].Quantity, L.Name AS LocationNameFROM Production.Product AS PINNER JOIN Production.ProductInventory AS [PI] ON P.ProductID = [PI].ProductIDINNER JOIN Production.Location AS L ON [PI].LocationID = L.LocationIDWHERE P.Name LIKE 'Touring%'ORDER BY P.Name DESC, L.Name DESC;
The following screenshot shows the results in the specified order:
Read now
Unlock full access