lesson 31: querying a database. 2 learning objectives after studying this lesson, you will be able...

20
Lesson 31: Querying a Database

Upload: muriel-jenkins

Post on 11-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Lesson 31: Querying a Database

Page 2: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

2

Learning Objectives

After studying this lesson, you will be able to:

Create, save, and run select queries

Design a query using multiple tables

Set query criteria

Define a query sort order

Create and format a calculated field

Use functions in query expressions

Create a crosstab query

Create unmatched and duplicates queries

Page 3: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Queries Defined

Queries are database objects that enable you to ask

questions of a database in order to retrieve data and

extract records that meet specific criteria

3

Page 4: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Reviewing Query Features Query results datasheet data remains stored in its

original table rather than in the query Data edited in a query results datasheet changes data

stored in a table Queries are dynamic objects that display up-to-date

data stored in database tables Queries can be used to create forms and reports

containing fields from multiple tables Query results datasheets enable you to filter or

organize data using the same techniques you use to filter and organize table datasheets

4

Page 5: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Creating Select Queries

Access contains two distinct tools for creating select

queries:

Query Wizard

Design View

5

Page 6: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Using the Simple Query Wizard

Steps you through the creation of a select query Enables you to identify table(s) and fields from each

table that you want to include in the query Prompts you to save the query

6

Page 7: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Using Query Design View Presents a split window with table field lists at the top

and columns and rows at the bottom

7

Page 8: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Adding Fields to the Query Grid Double-click a field name to add the field to the next

available column of the query design grid Drag a field to the next column in the grid Click the Field row of a column in the query grid and

selecting the field from the drop-down list Double-click the asterisk (*) that appears at the top of

the field list to add all fields to the grid Double-click the field list title bar to place each field in

the table in a separate column of the query grid.

8

Note! When you use the asterisk to add all fields, Access places

the table name in field row, but when you run the query, each field

appears in a separate column of the query results datasheet.

Page 9: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Setting Query Criteria

9

Comparison

OperatorWildcard Value Dates Wildcard

Page 10: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

10

Setting AND and OR Criteria

AND Criteria OR Criteria

Page 11: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Sorting a Query and Limiting Results

Sorting Query Results

Using sort tools after running the query

Setting a sort order in the query grid Sort row

11

Page 12: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Limiting Results Effective way of limiting results combines sorting with

restricting the number of results to display The Return feature on Query Design tab enables you

to set the number of records you want to retrieve

12

Page 13: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Please Excuse My Dear Aunt Sally

Parentheses

Exponentials

Multiplication/Division

Addition/Subtraction

(2+2)*32=6/2=33

13

Page 14: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Calculated Fields

Have no value of their own

Perform calculations using other field values

Calculated

field name

Field names from

existing tables

Arithmetic or

comparison

operator

14

Page 15: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Using Functions in Queries Groups query results by field on which a sum or

average or other order is required Multiple fields and calculated fields can be used for

grouping Example shows minimum, maximum, and average

15

Page 16: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Crosstab Queries

Rearranges data for summarizing

Groups data and totals values

16

Page 17: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

17

Crosstab Query Palette

Groupings appear as row and column headings

Summarized values appear in the TOTAL area

Page 18: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Unmatched and Duplicates Queries

Checks database tables to ensure there is no

duplication of records

Also checks database to ensure that records

referenced in one table have a matching record in the

other table

Hoped-for result of running these two queries is that

Access finds nothing to report

18

Page 19: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Structured Query Language

The underlying structure created for queries in Access

19

Page 20: Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design

Lesson 31: Querying a Database