CRITICAL SKILL 2.5

Order Data

So far, all of our select queries have returned records in random order. Earlier, we selected records from the customer table where the customer was located in either Connecticut or Utah and had a credit limit of $15,000. The results came back in no apparent order. It is often desirable to order the result set on one or more of the selected columns. In this case, it probably would have been easier to interpret the results if they were sorted by state, and within that state were then sorted by customer ID. Let’s take a look at the query syntax and resulting output:

SQL> select cust_id, cust_state_province, cust_credit_limit 2 from customers 3 where cust_credit_limit = 15000 4 and cust_state_province in ('UT','CT') ...

Get Oracle Database 10g: A Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.