Database Reference
In-Depth Information
The query results appear in Figure 3-32.
91
Customers are
sorted alphabetically
by name
FIGURE 3-32
Query results
EXAMPLE 17
List the number, name, street, and credit limit of all customers. Order the customers by name within des-
cending credit limit. (In other words, sort the customers by credit limit in descending order. Within each
group of customers that have a common credit limit, sort the customers by name.)
When you need to sort data on two fields, the more important sort key is called the major sort key (also
referred to as the primary sort key) and the less important sort key is called the minor sort key (also referred
to as the secondary sort key). In this case, because you need to sort the output by name within credit limit,
the CreditLimit field is the major sort key and the CustomerName field is the minor sort key. If there are two
sort keys, as in Example 17, the major sort key will be listed first. You can specify to sort the output in des-
cending (high-to-low) order by following the sort key with the word DESC, as shown in Figure 3-33.
Descending
order
Minor (secondary)
sort key
Major (primary)
sort key
FIGURE 3-33
SQL query to sort data on multiple fields
Search WWH ::




Custom Search