![]() As a side note, if you use the TOP keyword without the
specification of an ORDER BY clause, the TOP keyword will
base its selection of records on the order in which records
appear in the table. Additionally, if there are fields with dupli-
cate values, then Microsoft Access will display all duplicate
values. For example, if duplicate values exist and you specify to
receive TOP (n), you will receive the number of records you
specified, plus any duplicates that exist. The TOP keyword is
extremely useful when processing large sets of records. If you
are interested in just getting the general idea of a query, it is far
quicker to grab just a few records than it is to process all the
records.
The following example demonstrates using the TOP key-
word to display the bottom records.
Example 10
Suppose you want to display the three company names with the
lowest postal code from the Manufacturers table in Figure 4-18.
Look at the following script:
SELECT TOP 3 CompanyName, PostalCode
FROM Manufacturers
ORDER BY PostalCode;
In the preceding script, the ORDER BY clause sorts the Postal-
Code column in descending order, and the TOP 3 specification
displays only the top three records from the ORDER BY clause.
Look at Figure 4-20.
U
Note: The TOP keyword is used to display records that fall at
the top or bottom of a range that is specified by an ORDER BY
clause. When you combine the TOP and ORDER BY keywords to
65
3
Retrieving Records
Figure 4-20. Results (output)
|
|