microsoft access querying a database using the select query window

19
Microsoft Access Querying a Database Using the Select Query Window

Post on 20-Dec-2015

239 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Microsoft Access Querying a Database Using the Select Query Window

Microsoft Access

Querying a Database Using the Select Query Window

Page 2: Microsoft Access Querying a Database Using the Select Query Window

Objectives

• Creating and running queries

• Using compound criteria in queries

• Sorting data in queries

• Using a saved query

• Joining tables in queries

• Performing calculations in queries

• Using a grouping in queries

Page 3: Microsoft Access Querying a Database Using the Select Query Window

Types of Queries

• Queries can be used to view, and analyze information in a database

• In addition, update queries can be used to change data

• Types of queries:– Select queries– Parameter queries– Update queries– Crosstab queries

• Saved queries can be used to generate reports

Page 4: Microsoft Access Querying a Database Using the Select Query Window

Creating Select Queries

• Most common of all queries. Data can be retrieved from one or more tables; results are displayed in datasheet view

• Select a basis table for the query

• Click on the New Object button arrow, and select Query

• Select Design View and click OK

• Double click on basis table fields to insert them into the query

• Run the query

Page 5: Microsoft Access Querying a Database Using the Select Query Window

Select Query Datasheet View

Page 6: Microsoft Access Querying a Database Using the Select Query Window

Creating Parameter Queries

• Parameter queries prompt a user for search criteria with its own dialog box

• Start with a Select Query, and save as Client Parameter Query

• Add bracketed text in a criteria field to prompt the user for parameter value

Page 7: Microsoft Access Querying a Database Using the Select Query Window

Parameter Query Datasheet View

Page 8: Microsoft Access Querying a Database Using the Select Query Window

Creating Update Queries

• Update queries are used to make global data changes in one or more tables

• Start with a select query, save as Client Update Query

• In the Query menu, select Update Query

• Enter the new value in the Update To field

• Enter the old value to search for in the Criteria field

• Run the query, confirm changes

Page 9: Microsoft Access Querying a Database Using the Select Query Window

Review Changed Database

• All occurrences of 53 in the Trainer Number field have been updated to 42 in the Client table

Page 10: Microsoft Access Querying a Database Using the Select Query Window

Creating Crosstab Queries• Crosstab queries are used to

display aggregate data (such as count, total, average) in matrix format

• Start with a Select Query, save as Client Crosstab Query

• In the Query menu, select Crosstab Query

• Select Clear Grid in the Edit menu• Double click the City, Trainer

Number, and Amount Paid fields from the Client table

• Add a field named Total Paid: Amount Paid

• Refer to the picture for the Total and Crosstab settings

• Run the query, confirm aggregate data is correctly displayed

Page 11: Microsoft Access Querying a Database Using the Select Query Window

Crosstab Query Datasheet View

Page 12: Microsoft Access Querying a Database Using the Select Query Window

Using a Saved Query for Reports

• A saved query can be used for generating reports• Select a saved query listed in Queries Objects• Click on the New Object button arrow and select Report• Select Report Wizard and click OK• Pick fields you wish to see on the report• Can add grouping level(s)• Can sort records by up to four fields• Specify layout and style, and save the report• Click Finish to generate report

Page 13: Microsoft Access Querying a Database Using the Select Query Window

Using Compound Criteria in Queries

• Queries can contain compound search criteria

• AND clauses are specified by entering criteria on the same row across different fields

• OR clauses are specified by entering criteria on rows below other fields

• Can combine AND with OR clauses

• Can use wildcards to specify groups of items

• Specifies clients whose names start with an F AND has paid less than 20000, OR any Client Number that starts with a CE

Page 14: Microsoft Access Querying a Database Using the Select Query Window

Compound Criteria Datasheet View

Page 15: Microsoft Access Querying a Database Using the Select Query Window

Sorting Data in Queries

• Any field in a query can be sorted in ascending or descending order

• In Design View, look for the field to sort by (i.e. Amount Paid)

• Click on the Sort pull-down menu, and select Ascending or Descending

• Run the Query, and confirm data was sorted properly

Page 16: Microsoft Access Querying a Database Using the Select Query Window

Data Sorted by Amount Paid

Page 17: Microsoft Access Querying a Database Using the Select Query Window

Joining Tables in Queries

• Data needed for queries often reside on different tables. A join allows queries to retrieve relevant records from related tables

• Use the Trainer table as basis for a new query, and add the Client table into the query. Trainer Number joins the two tables in the query

Page 18: Microsoft Access Querying a Database Using the Select Query Window

Trainer and Client Tables Joined by Trainer Number

Page 19: Microsoft Access Querying a Database Using the Select Query Window

Performing Calculations in Queries

• Create a new field to display calculations based on the values of fields in a database

• Within Design View– Type an expression in an

empty cell in the Field row

– Field names must be bracketed (i.e. [Amount Paid])

• The following calculates the Taxes Paid by multiplying the Amount Paid by the CA sales tax rate