Access
Project 2
Querying a Database
Using the Select Query Window
Select
Query Window
(2 parts)
- Top portion - contains fields of tables which can be used in query
- Bottom portion - contains field, show, criteria, sort, and total information that can be used to set-up the query parameters
Note: dynamic because if table changes on which the query depends the results of query will change along with it.Note: Run button changes to Print Preview
2 Views of Query
- Design View - used to set-up query
- Print Preview View - shows dynaset of query
General Terms
Wildcards
2 Special kinds
- Asterisk (*) - collection of characters
- Question mark (?) - individual character
Example: criteria row Fa* for Name fieldCreating a Parameter Query
- parameter query - query that prompts for input whenever it is run.
- enter a parameter at run-time, rather than a specific value in the criteria row of the QBE grid
- created by enclosing a value (prompt) in Criteria row in square brackets
- important that value in brackets is not an existing field name
Example: [Enter City] for City field in Criteria rowNote: parameter queries useful in cases where query run frequently with slight changes to criteria.
Using
Compound Criteria
(2 types)
Sorting Data in Query |
Note: cant sort on an asterisk (used to add all fields of table to QBE grid)Note: major key must appear to left of minor key in QBE grid (if another order is desired in dynaset, must include major key twice in QBE grid and hide leftmost major key)
Creating a Top-Values Query
- top-values query - query that allows you to quantify the results.
- show only specified number of records or a percentage of records.
- sort records, limit results having highest or lowest values
- uses Top Values box on Query Design toolbar
Example find top 25%: click Top Values Box and select 25% after sorting the data in descending order.
- Join tables - find records in two tables having identical values in matching fields
Note: One of the key features that distinguishes DBMS from file systems is the ability to join tables. (create queries that draw on data from two or more tables)Note: Several types of joins are available, the kind used here in called a natural join the most common type.
Example: Net Pay:[Gross Pay] - [Deductions]
Note: Field Names in expression must be enclosed in brackets
Calculating Statistics
Grouping
Crosstab Queries
End