>
Part | Description |
fieldlist | The name of the field or fields to be retrieved along with any field-name aliases, SQL aggregate functions, selection predicates (ALL, DISTINCT, DISTINCTROW, or TOP), or other SELECT statement options. |
table | The name of the table from which records are retrieved. For more information, see the FROM clause. |
selectcriteria | Selection criteria. If the statement includes a WHERE clause, the Microsoft Jet database engine orders values after applying the WHERE conditions to the records. |
field1, field2 | The names of the fields on which to sort records. |
SELECT LastName, FirstName
FROM Employees
ORDER BY LastName;
SELECT LastName, FirstNameTo sort in descending order (Z to A, 9 to 0), add the DESC reserved word to the end of each field you want to sort in descending order. The following example selects salaries and sorts them in descending order:
FROM Employees
ORDER BY LastName ASC;
SELECT LastName, SalaryIf you specify a field containing Memo or OLE Object data in the ORDER BY clause, an error occurs. The Jet database engine doesn't sort on fields of these types. ORDER BY is usually the last item in an SQL statement. You can include additional fields in the ORDER BY clause. Records are sorted first by the first field listed after ORDER BY. Records that have equal values in that field are then sorted by the value in the second field listed, and so on. See Also ALL, DISTINCT, DISTINCTROW, TOP Predicates; GROUP BY Clause; HAVING Clause; SELECT Statement; SELECT...INTO Statement; SQL Aggregate Functions. Specifics (Microsoft Access) In Microsoft Access, an ORDER BY clause sorts the displayed data on a specified field or fields in ascending or descending order. Using an ORDER BY clause is equivalent to selecting Ascending or Descending in a Sort cell in the query design grid. Example The SQL statements shown below use the ORDER BY clause to sort records alphabetically and then by category. This example sorts the records by last name in descending order (Z to A).
FROM Employees
ORDER BY Salary DESC, LastName;
SELECT LastName, FirstName FROM Employees ORDER BY LastName DESC;This example sorts by category ID first, and then by product name.
SELECT CategoryID, ProductName, UnitPrice FROM Products
ORDER BY CategoryID, ProductName;