Brettb.Com
  HOME | ABOUT ME | BIOTECHNOLOGY | ARTICLES | GALLERY | CONTACT
Search: Go
TECHNICAL ARTICLES
 ASP
 ASP.NET
 JavaScript
 Transact SQL
 Other Articles
 Software Reviews

PHOTO GALLERIES
 Canon EOS 300D Samples
 Akihabara Maids!
 More Galleries...

TRAVEL LOG
 2009: China
 2008: Tokyo
 2007: Tokyo
 2006: Hong Kong
 2005: New York City

MORE STUFF
 Search Engine Optimisation
 Build an ASP Search Engine
 My Tropical Fishtank
 Autoglass
 SQL Month Name
 SQL Get Date Today
 SQL Year Month
 Other New Stuff...

POPULAR STUFF
 Regular Expressions
 Index Server & ASP
 JavaScript Ad Rotator

Home > Articles > Transact SQL Programming Articles

Using the Transact SQL Order Desc Ordering Statement

The SQL Desc keyword can be used to change the order that rows are returned in a results set if the Order By clause is used in a query. If Desc is specified then the results are ordered in descending order.

This SQL statement retrieves a list of products:

SELECT * FROM Products

This SQL statement will retrieve the products from the Products table in alphabetical order:

SELECT * FROM Products ORDER BY ProductName

Note that null values for ProductName will appear first.

If the Desc keyword is used then the ordering of the rows will be reversed, so that product names beginning with Z will be at the top of the list.

SELECT * FROM Products ORDER BY ProductName DESC

The Desc keyword can also sort numerical column values so that if Desc is used the highest values are shown first.

There is also an Asc keyword, but since this is the default ordering for SQL results set rows it's not always required.

Useful Links

  Site Map | Privacy Policy

All content is 1995 - 2012