Basic Queries  «Prev  Next»

Lesson 4 Using ORDER BY
Objective Sort results using ORDER BY.

SQL-Server 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 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:
1) Order By 1 2) Order By 2 3) Order By 3 4) Order By 4 5) Order By 5 6) Order By 6 7) Order By 7 8) Order By 8 9) Order By 9
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