Basic Queries  «Prev  Next»

SQL ORDER BY - Exercise

Objective: Sort customer query results using multiple keys.

Exercise scoring

Three-point self-assessment. Submission displays a model answer and rubric; no automatic SQL grader awards points.

Scenario and prerequisites

Use this small VirtualBookShelf teaching schema: CustTable(CustNo, ST, LName, FName). Assume CustNo is a unique, non-null customer identifier, and ST and LName contain non-null character values. Character sorting follows the database collation.

These legacy teaching table names are defined here for this exercise; the modern lesson uses other sample tables. No ASP download or database connection is required.

Instructions

Write a SELECT statement returning CustNo, ST, LName and FName, sorted first by state (ST) ascending and then by last name (LName) ascending. For equal state and last name, use CustNo ascending as a final tie-breaker.

Enter SQL directly, without an ASP querystring assignment. This website displays your answer for comparison; it never executes it.