Database Reference
In-Depth Information
We can sort by two columns by adding a second column name. For example, to sort first
by OrderNumber and then by Price within OrderNumber, we use the following SQL query:
/* *** SQL-Query-CH02-11 *** */
SELECT *
FROM ORDER_ITEM
ORDER BY OrderNumber, Price;
The result for this query is:
If we want to sort the data by Price and then by OrderNumber, we would simply reverse
the order of those columns in the ORDER BY clause as follows:
/* *** SQL-Query-CH02-12 *** */
SELECT *
FROM ORDER_ITEM
ORDER BY Price, OrderNumber;
with the results:
By The Way Note to Microsoft Access users: Unlike the Microsoft SQL Server out-
put shown here, Microsoft Access displays dollar signs in the output of
currency data.
By default, rows are sorted in ascending order. To sort in descending order, add the
SQL DESC keyword after the column name. Thus, to sort first by Price in descending order
and then by OrderNumber in ascending order, we use the SQL query:
/* *** SQL-Query-CH02-13 *** */
SELECT *
FROM ORDER_ITEM
ORDER BY Price DESC, OrderNumber ASC;
 
Search WWH ::




Custom Search