The ORDER BY clause can be used to dictate the order of the records returned (i.e., how they are sorted).
SELECT ToonType AS Type, CharacterName AS Name FROM Toons
WHERE ToonType = 'Duck' OR ToonType = 'Mouse'
ORDER BY ToonType, CharacterName;
Type Name
Duck Daffy Duck
Duck Daisy Duck
Duck Donald Duck
Mouse Jerry
Mouse Mickey Mouse
Mouse Minnie Mouse
(6 row(s) affected)
The preceding example returns records listed primarily in order of toon type (duck then mouse), and then for each type the relevant names are also listed in alphabetical order.
SELECT Item, Unitprice AS Price
FROM Products
ORDER BY Item, UnitPrice DESC;
Item Price
Dell Axim X30 379.00
Dell Axim X30 279.00
Dell Axim X30 249.00
Dell Flat Panel LCD Monitor 1000.00
Dell Flat Panel LCD Monitor 900.00
Dell Flat Panel LCD Monitor 700.00
Dell Inspiron 2650 1800.00
Dell Inspiron 2650 1650.00
Dell Inspiron 2650 1500.00
Dell Inspiron 300m 1600.00
Dell Inspiron 300m 1600.00
Intellisense Mouse 20.00
Intellisense Mouse 18.00
Travelstar 30gb Hard Drive 100.00
(14 row(s) affected)
You can specify descending order (the default is ascending order) by adding the reserved word DESC after the field name. This example returns a list of all items in ascending alphabetical order along with their prices in descending numerical order.