SQLConfiguration SQLConfiguration

Basic Queries  «Prev  Next»
Lesson 4 Using ORDER BY
Objective Sort results using ORDER BY.

Sort Results Using Order By

The basic SELECT statement usually returns rows in the same order as they appear in the table. Most of the time you will probably want to output results arranged in a specific order. The ORDER BY clause is used to sort the results by one or more columns. Columns are sorted in ascending or descending order.
Note: unless otherwise specified, columns will be sorted in ascending order by default.
Suppose you want to sort the VirtualBookShelf.com BookTable by title. The following SELECT statement does just that and returns the columns in ascending order: 
SELECT * FROM BookTable 

Notice that the ORDER BY clause comes at the end of a query.

The following SlideShow shows this statement in action:

Order by Clause
In the next lesson, you will modify rows using the UPDATE statement.

Order By Clause - Exercise

Click the Exercise linkn below to practice using the ORDER BY clause.
Order By Clause - Exercise