The ASC keyword is used to sort the
records of a set in ascending order. The ASC keyword is used in
conjunction with the ORDER BY expression. The formula to follow is:
SELECT What FROM WhatObject ORDER BY WhatField;
The field used as the basis must be recognized as part
of the selected columns. Imagine you have created a list of staff members
made of their first and last names in a table named Employees. If you want
to order the list in alphabetical order based on the LastName column, you
would use a statement such as:
SELECT FirstName, LastName FROM Employees ORDER BY LastName;
If you use the * operator to include all fields, you
can order the list based on any of the table's fields, as we learned
during data analysis. Imagine that you have created a query that includes
all fields. The following statement would list the records of the
Employees table based on the alphabetical order of the LastName column:
SELECT * FROM Employees ORDER BY LastName;
By default, records are ordered in ascending order.
Nevertheless, the ascending order is controlled using the ASC
keyword specified after the based field. For example, to sort the last
names in ascending order of a query that includes the first and last
names, the above statement can also be written as follows:
SELECT FirstName, LastName FROM Employees ORDER BY LastName ASC;
The second statement can be written as:
SELECT * FROM Employees ORDER BY LastName ASC;