Collection Contents Index Looking at the information in a table Selecting columns from a table pdf/chap12.pdf

First Guide to SQL Anywhere Studio
   PART 3. Basic SQL
     CHAPTER 12. Selecting Data from Database Tables       

Ordering query results


Unless otherwise requested, the database server returns the rows of a table in no particular order. Often it is useful to look at the rows in a table in a more meaningful sequence. For example, you might like to see employees in alphabetical order.

The following example shows how adding an ORDER BY clause to the SELECT statement causes the results to be retrieved in alphabetical order.

  To list the employees in alphabetical order:
  1. Type the following:

    SELECT * FROM employee ORDER BY emp_lname

emp_id

manager_id

emp_fname

emp_lname

dept_id

1751

1576

Alex

Ahmed

400

1013

703

Joseph

Barker

500

591

1576

Irene

Barletta

400

191

703

Jeannette

Bertrand

500

1336

1293

Janet

Bigelow

300

Notes 

The order of the clauses is important. The ORDER BY clause must follow the FROM clause and the SELECT clause.


Collection Contents Index Looking at the information in a table Selecting columns from a table pdf/chap12.pdf