Monday, 18 June 2012

Lesson 9: Displaying Rows in Descending Order in SQL




If you would like to see fields displayed in descending order, follow the field name with "desc" in the Order By clause.

Syntax:
Select */fieldname ...
from tablename
order by fieldname <desc> ...

Explanation:
  • By default, the Order By clause tells SQL you want the field displayed in ascending order.
  • Typing "desc" after the field name in the Order By clause tells SQL you want the data in the field displayed in descending order (Z to A, 100 to 1).
Example:
Retrieve the city, vendor ID, and name from the TrnVendor table. Order your data by city in descending order:
  1. In the SQL text box, type:
Select City, VendId, Name 
from TrnVendor
order by City desc;
  1. Execute the SQL statement.
Results
 
CityVendIdName
YoungstownTV018Computer Bytes
WarrenTV002The Games All Here
ToledoTV027Narrow Nest
ToledoTV014Counter Productive
ToledoTV009Hit the Deck
ToledoTV001Wet Off Towels
Park RidgeTV015No Waste Disposal










No comments:

Post a Comment