O'Reilly logo

Absolute Beginner’s Guide to Databases by John V. Petersen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Organize Output I: Use the Order By Clause

Just as you will always use the Where clause to filter irrelevant data, you will always use the Order By clause to sort the data in your resultset. Furthermore, based on the fields you choose to sort the data, you will want to sort the data ascending, descending, or some combination thereof. All of these operations are accomplished with the Order By clause. To illustrate how the Order By clause works, consider the following code:

SELECT  lastname  + ",  " + firstname As client
   From Client
   Where ClientType = "I"
   Order By lastname

Figure 8.13 illustrates the results of this query.

Figure 8.13. The Order By clause allows you to sort the data in your resultset.

By default, any field you select to order ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required