Data retrieval - Introduction to the
SELECT statement.
One of the
DML commands, used for retrieving specific data from one or more tables,
reporting calculated results based on the data retrieved, or displaying the
results of “what if?” type calculations.
Example:
1. Run the query Current Product List.
2. Change to SQL view to see the SELECT statement
3. Close the query.
Exercise: Create a list of all product categories
1. Type the following statement in the SQL
window:
SELECT *
FROM Categories
2. View the results without saving by clicking the
View button (switches to Datasheet view).
3. Change back to SQL view and run the statement
by clicking the Run ( ! ) button.
4. Save the query (e.g., AllCategories) and
close it.
Exercise: Create a phone list of customer
contacts (just company and contact names with phone and FAX numbers) sorted by
company name.
1. Type the following statement in the SQL
window:
SELECT CompanyName, ContactName,
Phone, Fax
FROM Customers
ORDER BY CompanyName
2. View the results; then run and save the query
as AllCustomers. You should see 91
customers.
3. Modify the list to include only customers
from the
SELECT CompanyName AS Company,
FROM Customers
WHERE Country = “
ORDER BY CompanyName
4. View the results; then run and save the query
as UKCustomers (7 customers)
5. Close the query.