Database Reference
In-Depth Information
The query results appear in Figure 3-30.
90
Only customers with credit
limits of $7,500, $10,000,
or $15,000 are listed
FIGURE 3-30
Query results
SORTING
Recall that the order of rows in a table is considered to be immaterial. From a practical standpoint, this
means that when you query a relational database, there are no guarantees concerning the order in which the
results will be displayed. The results might appear in the order in which the data was originally entered, but
even this is not certain. Thus, if the order in which the data is displayed is important, you should specifically
request that the results be displayed in a desired order. In SQL, you sort data using the ORDER BY clause.
EXAMPLE 16
List the number, name, street, and credit limit of all customers. Order (sort) the customers by name.
The field on which to sort data is called a sort key. To sort the output, you include the words ORDER BY
in the SQL query, followed by the sort key field, as shown in Figure 3-31.
ORDER BY
clause
Sort key
FIGURE 3-31
SQL query to sort data
Search WWH ::




Custom Search