Microsoft Access User Manual
Anúncio
Anúncio
C H A P T E R
Performing Queries
perForManCe oBJeCtiVes
Upon successful completion of Chapter 3, you will be able to:
•
Design queries to extract specific data from tables
•
Modify queries
•
Design queries with Or and And criteria
•
Use the Simple Query Wizard to create queries
•
Create a calculated field
•
Use aggregate functions in queries
•
Create crosstab, duplicate, and unmatched queries
Tutorials
3.1 Creating a Query in Design View
3.2 Extracting Records Using Criteria
Statements
3.3 Creating a Query in Design View
Using Multiple Tables
3.4 Extracting Records Using AND
Criteria; Sorting Query Results
3.5 Renaming and Deleting Objects
3.6 Extracting Records Using OR
Criteria
3.7 Creating Queries Using the Simple
Query Wizard
3.8 Performing Calculations in a Query
3.9 Using Aggregate Functions
3.10 Creating a Crosstab Query
3.11 Creating a Find Duplicates Query
3.12 Creating a Find Unmatched Query
One of the primary uses of a database is to extract the specific information needed to answer questions and make decisions. A company might need to know information such as how much inventory is currently on hand, which products have been ordered, which accounts are past due, or which customers live in a particular city. You can extract specific information from a table or multiple tables by completing a query. You will learn how to perform a variety of queries on information in tables in this chapter. Model answers for this chapter’s projects appear on the following pages.
Access
al1C3
Note: Before beginning the projects, copy the AL1C3 subfolder from the AL1 folder on the CD that accompanies this textbook to your storage medium and make AL1C3 the active folder.
77
Project 1
Design Queries
Project 1a
Relationships for AL1-C3-Dearborn
Thursday, October 8, 2015
Clients
ClientID
RepID
Client
StreetAddress
City
State
ZipCode
Telephone
Dearborn Relationships
Sales
SalesID
ClientID
CalendarYear
Sales
ClientsIndianapolisQuery
Client StreetAddress City
Fairhaven Developers 574 East Raymond Street Indianapolis IN
Landower Company 1299 Arlington Avenue Indianapolis IN
State
Harford Systems
Gallagher Systems
Blue Ridge, Inc.
Alderton Metals
9654 Jackson Street
3885 Moore Avenue
29 South 25th Street
Indianapolis IN
Indianapolis IN
Indianapolis IN
103 South Parker Avenue Indianapolis IN
DV Corporation
Wheeling Products
210 West Michigan Stree Indianapolis IN
5567 Washburn Avenue Indianapolis IN
Martin Manufacturing 422 West Morris Street Indianapolis IN
Valley Construction 123 46th Street Indianapolis IN
AeroTech
Miles & Harrisburg
Haute Contractors
Eagleton Industries
9905 West 16th Street
11029 47th Street East
422 Kessler Boulevard
544 Eastridge Drive
Zinn-Harris Electronics 675 South Holt Road
Indianapolis IN
Indianapolis IN
Indianapolis IN
Indianapolis IN
Indianapolis IN
ZipCode
46219-3005
46236-1299
46247-9654
47229-1075
46227-1355
47220-1450
46251-4503
46247-5567
46238-4220
46242-1230
46241-9905
46238-1120
46218-4220
47230-5440
47221-0551
ClientsIndianapolisQuery
Representatives
RepID
RepName
Telephone
QuotaID
Benefits
RepID
HireDate
Vacation
HealthBenefits
10/8/2015
RepsWith765AreaCodeQuery
RepName
Lee Hutchinson
Isabelle Marshall
Lydia Alvarado
Telephone
Orders Table
(765) 555-4996
RepsWith765AreaCodeQuery
QuotaIDGreaterThanTwoQuery
RepName
Catherine Singleton 3
Isabelle Marshall
Maureen Pascual
3
3
Linda Foster
Kwan Im
William Ludlow
Lydia Alvarado
Alfred Silva
Gina Tapparo
5
5
4
4
3
4
QuotaID
QuotaIDGreaterThanTwoQuery
Quotas
QuotaID
Quota
10/8/2015
10/8/2015
122
123
125
127
115
118
119
121
107
108
109
112
101
103
104
105
122
123
125
127
113
115
118
119
105
107
109
112
101
ClientID
102
103
$327,541.00
$144,328.00
$130,239.00
$441,000.00
$221,379.00
$105,000.00
$721,923.00
$200,540.00
$103,400.00
$175,011.00
$222,133.00
$103,435.00
$125,900.00
$265,439.00
$120,890.00
$176,420.00
Sales
$289,563.00
$101,210.00
$125,436.00
$215,420.00
$199,346.00
$554,120.00
$138,560.00
$141,670.00
$115,423.00
$156,439.00
$222,133.00
$174,319.00
$300,137.00
$151,003.00
$214,000.00
SalesOver$99999Query
SalesOver$99999Query
Project 1b
Relationships for AL1-C3-CopperState
Thursday, October 8, 2015
Clients
ClientID
FirstName
LastName
StreetAddress
City
State
ZIP
Telephone
Agents
AgentID
OfficeID
FirstName
LastName
Telephone
Coverage
LicenseNo
ClientID
Medical
Liability
Comprehensive
UninsMotorist
Collision
Assignments
ClientID
OfficeID
AgentID
GoldStatus
Claims
ClaimID
ClientID
LicenseNo
DateOfClaim
AmountOfClaim
Page 1
Offices
OfficeID
Address
City
State
ZIP
Telephone
Page 1
RepName
Alfred Silva
Cecilia Ortega
Isabelle Marshall
HireDate
3/15/2011
4/12/2011
3/7/2011
MarToNov2011HiresQuery
Feb1-28OrdersQuery
250-L
255-XL
299-W4
299-W5
602-XR
590-TL
299-W3
299-W1
560-TL
ProductID
250-XL
100-02
202-CW
201-CW
100-05
101-S3R
101-S3B
255-M
Product
Cascade R4 jacket, MXL
Multi-function compass
Ten-piece hiker cookware
Eight-piece stainless steel cookware
Deluxe map compass
SL 20-degrees synthetic sleeping bag, red
SL 20-degrees synthetic sleeping bag, blac
Cascade R4 jacket, WM
Cascade R4 jacket, ML
Cascade R4 jacket, WXL
HT waterproof hiking boots, WS8
HT waterproof hiking boots, WS7
Binoculars, 8 x 42
Thermaline roll-top table
HT waterproof hiking boots, WS9
HT waterproof hiking boots, WS11
Thermaline sleeping pad
Feb1-28OrdersQuery
OrderDate
2/2/2015
2/2/2015
2/2/2015
2/2/2015
2/2/2015
2/2/2015
2/2/2015
2/2/2015
2/2/2015
2/2/2015
2/16/2015
2/16/2015
2/16/2015
2/16/2015
2/16/2015
2/16/2015
2/16/2015
10/8/2015
FirstName
Spenser
Vernon
Paul
Spenser
10/8/2015
Eileen
Fredrick
Alice
Cecilia
Suzanne
Harold
Phillip
Parma
Carla
Eileen
Rachel
Marcus
Donald
Sun
Alan
Michael
Joanne
Lenora
Helena
Bonnie
Eric
7521
0214
8223
5665
9879
4852
6478
9775
ClientID
3120
7335
4300
3120
4852
5645
5645
9897
2768
7139
9872
5982
4875
1574
4786
5231
4567
4868
Hanley
Kaelin
LeVigne
Rutledge
Cheong
Couturier
Nicolo
Donnelly
Chisham
Myerson
Metzger
Zadinski
LastName
Winters
Cook
Vuong
Winters
Cole
Hanley
Guthrie
Ryckman
Ortiz
Lundberg
McDougal
Cole
Moreno
Waterman
UninsMotoristCoverageQuery
UninsMotorist
Page 1
RepsHiredIn2012Query
15
RepID
22
25
10/8/2015
RepName
Lee Hutchinson
Gina Tapparo
Lydia Alvarado
HireDate
2/1/2012
10/1/2012
4/1/2012
RepsHiredIn2012Query
BlueRidgeSalesQuery
UninsMotoristCoverageQuery
ClientID
110
110
Client
Blue Ridge, Inc.
Blue Ridge, Inc.
Sales
$17,542.00
$83,210.00
BlueRidgeSalesQuery
JanClaimsOver$500Query
8223
4300
8854
9879
4567
5982
ClientID
9383
7335
4300
9383
1574
4875
FirstName
Elaine
Vernon
Paul
Elaine
Joanne
Michael
Cecilia
Paul
Edward
Harold
Bonnie
Alan
LastName
Hueneka
Cook
Vuong
Hueneka
Donnelly
Nicolo
Ortiz
Vuong
Bakalarski
McDougal
Metzger
Couturier
ClaimID
102394
104366
121039
153001
158954
147858
158962
178545
174223
174589
136695
147851
DateOfClaim AmountOfClaim
1/2/2015 $1,235.00
1/5/2015
1/8/2015
$834.95
$5,230.00
1/17/2015
1/19/2015
1/16/2015
1/21/2015
1/30/2015
1/23/2015
1/26/2015
1/10/2015
1/12/2015
$535.00
$1,050.75
$875.00
$2,830.50
$4,858.30
$950.50
$752.45
$1,840.00
$3,250.50
JanClaimsOver$500Query
10/8/2015
10/8/2015
10/8/2015
10/8/2015
78
Access Level 1
■
Unit 1
Page 1
Page 1
Page 1
Page 1
Page 1
Page 1
GWClientsQuery
Project 1c
OrdersLessThan$1500Query
68
68
84
68
15
68
25
68
68
10
15
68
84
10
31
31
60
60
25
10
68
299-W3
299-W1
255-XL
255-M
560-TL
155-35
375-S
375-M
590-TL
209-XL
209-L
210-L
209-XXL
100-05
371-L
202-CW
155-20
201-CW
210-M
100-02
152-H
ProductID SupplierID UnitsOrdered
442-1B 42 10
780-2
250-XL
250-L
99
60
60
10
10
10
101-S3R
101-S3B
299-M3
299-M2
299-M5
299-W4
299-W5
54
54
31
31
31
31
31
10
10
10
10
10
10
10
25
20
5
10
5
20
5
25
25
15
5
15
10
15
10
8
5
5
20
10
20
$752.90
$602.32
$599.50
$599.50
$397.00
$199.50
$199.00
$199.00
$196.25
$180.00
$173.75
$162.25
$145.80
$129.75
$129.50
$124.25
$104.25
$99.75
$97.35
$45.95
$44.85
Amount
$1,495.00
$1,288.50
$1,285.00
$1,285.00
$1,199.50
$1,137.50
$887.90
$887.90
$887.90
$752.90
$752.90
OrdersLessThan$1500Query
GW
OfficeID
GW
GW
GW
GW
Carlos
Joanne
Cecilia
Donald
Paul
10/8/2015
LastName
Alvarez
Donnelly
Ortiz
Rutledge
Vuong
GWClientsQuery
SalesMoreThan$100000Query
RepName
Andre Kulisek
Andre Kulisek
Lee Hutchinson
Linda Foster
Kwan Im
Linda Foster
Kwan Im
Client
HE Systems
HE Systems
Harford Systems
Bering Company
Eagleton Industries
Bering Company
Eagleton Industries
Sales
$721,923.00
$554,120.00
$441,000.00
$327,541.00
$300,137.00
$289,563.00
$265,439.00
Craig Johnson
Craig Johnson
Miles & Harrisburg
Miles & Harrisburg
Catherine Singleton Gallagher Systems
Lee Hutchinson
$222,133.00
$222,133.00
$221,379.00
$215,420.00
Harford Systems
Catherine Singleton Zinn-Harris Electronics $214,000.00
Gina Tapparo DV Corporation
Catherine Singleton Gallagher Systems
Jaren Newman
David DeBruler
Cecilia Ortega
Alfred Silva
AeroTech
AeroTech
Dover Industries
$200,540.00
$199,346.00
Catherine Singleton Zinn-Harris Electronics $176,420.00
David DeBruler
Haute Contractors
Clearwater Service
Catherine Singleton Franklin Services
Gina Tapparo
Robin Rehberg
Jaren Newman
Alfred Silva
Cecilia Ortega
Craig Johnson
Edward Harris
William Ludlow
Craig Johnson
Kwan Im
DV Corporation
Landower Company
Haute Contractors
Clearwater Service
Dover Industries
Wheeling Products
Karris Supplies
Madison Electrics
Wheeling Products
Fairhaven Developers
$175,011.00
$174,319.00
$156,439.00
$151,003.00
$144,328.00
$141,670.00
$138,560.00
$130,239.00
$125,900.00
$125,436.00
$120,890.00
$115,423.00
$105,000.00
$103,435.00
$103,400.00
$101,210.00
SalesMoreThan$100000Query
10/8/2015
Project 1d
10/8/2015
SalesLessThan$100000Query
RepName
William Ludlow
Robin Rehberg
Kwan Im
Client
Madison Electrics
Landower Company
Fairhaven Developers
Isabelle Marshall
Maureen Pascual
Providence, Inc.
Blue Ridge, Inc.
Isabelle Marshall Providence, Inc.
Catherine Singleton Franklin Services
Lydia Alvarado
Edward Harris
Jaren Newman
Alfred Silva
Lydia Alvarado
Craig Johnson
Kwan Im
Craig Johnson
Lee Hutchinson
Jaren Newman
Maureen Pascual
Lee Hutchinson
Alfred Silva
Alfred Silva
Alfred Silva
Kwan Im
Martin Manufacturing
Karris Supplies
Paragon Corporation
Alderton Metals
Martin Manufacturing
Hoosier Corporation
Milltown Contractors
Hoosier Corporation
Valley Construction
Paragon Corporation
Blue Ridge, Inc.
Valley Construction
Northstar Services
Alderton Metals
Northstar Services
Milltown Contractors
Sales
$99,450.00
$97,653.00
$95,630.00
$85,628.00
$83,210.00
$75,462.00
$65,411.00
$61,539.00
$61,349.00
$51,237.00
$45,230.00
$35,679.00
$31,935.00
$31,230.00
$24,880.00
$22,478.00
$20,137.00
$17,542.00
$15,248.00
$15,094.00
$9,547.00
$9,457.00
$2,356.00
SalesLessThan$100000Query
RepsWith3WeekVacationsQuery
RepName
Alfred Silva
Cecilia Ortega
Isabelle Marshall
Craig Johnson
Gina Tapparo
Edward Harris
Vacation
3 weeks
3 weeks
3 weeks
3 weeks
3 weeks
3 weeks
RepsWith3WeekVacationsQuery
Page 1
Page 1
Project 1e
RepsWith3Or4WeekVacationsQuery
RepName
William Ludlow
Alfred Silva
Cecilia Ortega
Robin Rehberg
Isabelle Marshall
Craig Johnson
Gina Tapparo
Edward Harris
Vacation
4 weeks
3 weeks
3 weeks
4 weeks
3 weeks
3 weeks
3 weeks
3 weeks
RepsWith3Or4WeekVacationsQuery
Client City
Fairhaven Developers Indianapolis
Landower Company
Harford Systems
Harford Systems
Gallagher Systems
Gallagher Systems
DV Corporation
DV Corporation
Wheeling Products
10/8/2015
Wheeling Products
AeroTech
AeroTech
Miles & Harrisburg
Miles & Harrisburg
Haute Contractors
Haute Contractors
Eagleton Industries
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Indianapolis
Eagleton Industries Indianapolis
Zinn-Harris Electronics Indianapolis
Zinn-Harris Electronics Indianapolis
Sales
$101,210.00
$130,239.00
$215,420.00
$441,000.00
$199,346.00
$221,379.00
$138,560.00
$200,540.00
$115,423.00
$103,400.00
$156,439.00
$175,011.00
$222,133.00
$222,133.00
$174,319.00
$125,900.00
$300,137.00
$265,439.00
$214,000.00
$176,420.00
SalesOver$100000IndianapolisQuery
SkiHatsGlovesOnOrderQuery 10/8/2015
OrderID
1017
1009
1008
1012
1013
1016
1015
1014
SupplierName Product
Freedom Corporation Gordon wool ski hat, L
Freedom Corporation Gordon wool ski hat, XL
Freedom Corporation Gordon wool ski hat, XXL
Freedom Corporation Tech-lite ski hat, L
Freedom Corporation Tech-lite ski hat, M
Freedom Corporation Lite-tech ski gloves, ML
Freedom Corporation Lite-tech ski gloves, WM
Freedom Corporation Lite-tech ski gloves, WS
SkiHatsGlovesOnOrderQuery
UnitsOrdered
25
25
20
25
15
10
20
20
ClientsWithOnlyLiabilityQuery
FirstName
Brenda
LastName
Lazzuri
Medical Liability
Edward
Brenda
Bret
Carlos
Bakalarski
Lazzuri
Mardock
Alvarez
Customers Table
ClientsWithOnlyLiabilityQuery
Comprehensive UninsMotorist Collision
Page 1
10/8/2015
Suppliers25-31-42Query
31
31
31
31
31
31
31
42
42
42
42
25
25
31
31
31
31
SupplierID
25
25
SupplierName Product
Langley Corporation Thermaline sleeping pad
Langley Corporation Thermaline light-weight cot
Langley Corporation Thermaline camp seat
Langley Corporation Thermaline roll-top table
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
HT waterproof hiking boots, MS13
HT waterproof hiking boots, MS12
HT waterproof hiking boots, MS11
HT waterproof hiking boots, MS10
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
HT waterproof hiking boots, MS9
HT waterproof hiking boots, WS11
HT waterproof hiking boots, WS10
HT waterproof hiking boots, WS9
HT waterproof hiking boots, WS8
Sound Supplies
Sound Supplies
HT waterproof hiking boots, WS7
HT waterproof hiking boots, WS6
Fraser Valley Products Polar backpack, 150BR
Fraser Valley Products Polar backpack, 150RW
Fraser Valley Products Polar backpack, 250BR
Fraser Valley Products Polar backpack, 250RW
Suppliers25-31-42Query
Page 1
BootsSleepingBagsBackpacksQuery
ProductID
443-1B
101-S1B
101-S1R
101-S2B
101-S2R
101-S3B
Product
Polar backpack, 250RW
SL 0-degrees down sleeping bag, black
SL 0-degrees down sleeping bag, red
SupplierName
Fraser Valley Products
Manning, Inc.
Manning, Inc.
SL 15-degrees synthetic sleeping bag, blac Manning, Inc.
SL 15-degrees synthetic sleeping bag, red Manning, Inc.
SL 20-degrees synthetic sleeping bag, blac Manning, Inc.
SL 20-degrees synthetic sleeping bag, red Manning, Inc.
HT waterproof hiking boots, MS13 Sound Supplies
101-S3R
10/8/2015
299-M2
299-M3
299-M4
299-M5
299-W1
299-W2
299-W3
HT waterproof hiking boots, MS12
HT waterproof hiking boots, MS11
HT waterproof hiking boots, MS10
HT waterproof hiking boots, MS9
HT waterproof hiking boots, WS11
HT waterproof hiking boots, WS10
HT waterproof hiking boots, WS9
Page 1
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
299-W4
299-W5
HT waterproof hiking boots, WS8
HT waterproof hiking boots, WS7
Sound Supplies
Sound Supplies
299-W6
442-1A
442-1B
HT waterproof hiking boots, WS6
Polar backpack, 150BR
Polar backpack, 150RW
Sound Supplies
Fraser Valley Products
Fraser Valley Products
443-1A Polar backpack, 250BR Fraser Valley Products
Page 1
10/8/2015
10/8/2015
10/8/2015
10/8/2015
Chapter 3
■
Performing Queries
79
Page 1
Page 1
Page 1
Project 1f
ClientSalesQuery
Client
Bering Company
Bering Company
Fairhaven Developers
Fairhaven Developers
Clearwater Service
Clearwater Service
Landower Company
Landower Company
Harford Systems
Harford Systems
Providence, Inc.
Providence, Inc.
Gallagher Systems
Gallagher Systems
Karris Supplies
Karris Supplies
HE Systems
HE Systems
Blue Ridge, Inc.
Blue Ridge, Inc.
Alderton Metals
Alderton Metals
DV Corporation
DV Corporation
Franklin Services
Franklin Services
Milltown Contractors
Milltown Contractors
Wheeling Products
Wheeling Products
Martin Manufacturing
Martin Manufacturing
Valley Construction
Valley Construction
AeroTech
AeroTech
Miles & Harrisburg
Miles & Harrisburg
Paragon Corporation
Paragon Corporation
Madison Electrics
Madison Electrics
Haute Contractors
112
113
113
114
114
115
115
116
108
109
109
110
110
111
111
112
104
105
105
106
106
107
107
108
ClientID
101
101
102
102
103
103
104
116
117
117
118
118
119
119
120
120
121
121
122
$105,000.00
$554,120.00
$721,923.00
$17,542.00
$83,210.00
$9,547.00
$45,230.00
$138,560.00
$200,540.00
$141,670.00
$65,411.00
$2,356.00
$31,230.00
$115,423.00
$103,400.00
$35,679.00
Sales
$289,563.00
$327,541.00
$101,210.00
$95,630.00
$125,436.00
$144,328.00
$97,653.00
$130,239.00
$215,420.00
$441,000.00
$85,628.00
$75,462.00
$199,346.00
$221,379.00
$61,349.00
$61,539.00
$15,248.00
$22,478.00
$156,439.00
$175,011.00
$222,133.00
$222,133.00
$51,237.00
$20,137.00
$99,450.00
$103,435.00
$174,319.00
ClientSalesQuery, Page 1
Page 1
ClientSalesQuery
125
126
126
127
127
ClientID
122
123
123
124
124
125
Client
Haute Contractors
Eagleton Industries
Eagleton Industries
10/8/2015
Hoosier Corporation
Dover Industries
Sales
$125,900.00
$300,137.00
$265,439.00
$24,880.00
$31,935.00
$151,003.00
Dover Industries
Northstar Services
$120,890.00
$9,457.00
Northstar Services $15,094.00
Zinn-Harris Electronics $214,000.00
Zinn-Harris Electronics $176,420.00
ClientSalesQuery, Page 2
ProductOrderAmountsQuery
84
54
54
54
10
10
10
15
15
35
99
99
84
SupplierID
42
25
25
31
31
31
31
31
31
31
60
60
60
60
68
68
68
42
68
68
68
68
68
SupplierName ProductID
Fraser Valley Products 443-1B
Langley Corporation 560-TL
Langley Corporation 590-TL
Emerald City Products 602-XR
KL Distributions 647-1
KL Distributions
Macadam, Inc.
Macadam, Inc.
Manning, Inc.
Manning, Inc.
Manning, Inc.
Hopewell, Inc.
780-2
100-02
100-05
101-S2R
101-S3B
101-S3R
152-H
Hopewell, Inc.
Hopewell, Inc.
Bayside Supplies
Bayside Supplies
155-20
155-35
201-CW
202-CW
Freedom Corporation 209-L
Freedom Corporation 209-XL
Freedom Corporation 209-XXL
Freedom Corporation 210-L
Freedom Corporation 210-M
Cascade Gear
Cascade Gear
Cascade Gear
Cascade Gear
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Sound Supplies
Freedom Corporation 371-L
Freedom Corporation 375-M
Freedom Corporation 375-S
Fraser Valley Products 442-1B
250-L
250-XL
255-M
255-XL
299-M2
299-M3
299-M5
299-W1
299-W3
299-W4
299-W5
Page 2
Amount
$2,397.75
$397.00
$196.25
$2,145.00
$2,999.85
$1,288.50
$45.95
$129.75
$1,945.25
$1,137.50
$1,199.50
$44.85
$104.25
$199.50
$99.75
$124.25
$173.75
$180.00
$145.80
$162.25
$97.35
$1,285.00
$1,285.00
$599.50
$599.50
$887.90
$887.90
$887.90
$602.32
$752.90
$752.90
$752.90
$129.50
$199.00
$199.00
$1,495.00
ProductOrderAmountsQuery
Page 1
Project 1g
SuppliersNotBCQuery
SupplierName
Bayside Supplies
Hadley Company
Cascade Gear
Sound Supplies
StreetAddress
6705 North Street Bellingham WA
5845 Jefferson Street Seattle
540 Broadway
2104 Union Street
Emerald City Products 1059 Pike Street
KL Distributions 402 Yukon Drive
City
Seattle
Seattle
Seattle
Prov/State PostalCode
WA
WA
WA
WA
Bellingham WA
98432
98107
98106
98105
98102
96435
SuppliersNotBCQuery
ClientsMuncieQuery
Client
Bering Company
Clearwater Service
Providence, Inc.
StreetAddress
4521 East Sixth Street
City
Muncie
10385 North Gavin Street Muncie
12490 141st Street Muncie
Paragon Corporation 4500 Meridian Street
Dover Industries
Northstar Services
4839 Huchins Road
Muncie
Muncie
5135 West Second Street Muncie
ClientsMuncieQuery
IN
State
IN
IN
IN
IN
IN
ZipCode
47310-5500
47308-1236
47306-3410
47302-4338
47306-4839
47301-7774
PhoenixClientClaimsOver$500Query
10/8/2015
10/8/2015
ClientID
7335
1331
9879
9775
6478
4868
9879
FirstName
Vernon
Erin
Harold
Carla
Parma
Eric
Harold
LastName
Cook
Hagedorn
McDougal
Waterman
Moreno
Zadinski
McDougal
StreetAddress
1230 South Mesa
4818 Oakes Boulevard
7115 Elizabeth Lane
3979 19th Avenue
610 Sheridan Avenue
1301 North Meridian
7115 Elizabeth Lane
PhoenixClientClaimsOver$500Query
City
Phoenix
Phoenix
Phoenix
Phoenix
Phoenix
Phoenix
Phoenix
AZ
AZ
AZ
AZ
State
AZ
AZ
AZ
ZIP ClaimID AmountOfClaim
85018 104366 $834.95
85018 198745
85009 174589
85031 241485
$1,797.00
$752.45
$4,500.00
85031 200147
85031 210369
85009 247823
$925.75
$2,675.00
$775.75
10/8/2015
10/8/2015
Project 1h
PensionContributionsQuery
125
126
127
129
130
133
134
135
137
138
139
140
EmpID
101
102
103
104
105
106
108
FirstName
Joseph
Walter
Francine
Mary
Corey
Stephanie
Nathan
110
111
112
114
115
10/8/2015
118
Thomas
Ray
Noreen
Blaine
Sean
119
121
124
Silas
Glenn
Lucinda
Patricia
Antonio
Debra
Michelle
Kurt
Shilo
Norman
Brett
Sally
Dorothy
Leslie
Susan
Jerry
Kathleen
Tapparo
Vincent
Ziegler
Alvarado
Curis
Dupree
Farrell
Griswold
Jacobsen
Masui
Prentiss
Schreiber
LastName
Ammons
Irving
Prescott
Vanderhoff
Gadeau
Wendt
Holmes
Byrnes
Bannerman
Blanca
Kaiser
O'Callaghan
Workman
Ishimoto
Larsen
Ochoa
Silvestri
PensionContributionsQuery
Salary&PensionQuery
AnnualSalary PensionContribution
$52,350.00
$50,750.00
$52,500.00
1570.5
1522.5
1575
$59,750.00
$60,150.00
$42,000.00
$53,350.00
$42,500.00
$32,600.00
$38,750.00
$64,500.00
$52,455.00
1792.5
1804.5
1260
1600.5
1275
978
1162.5
1935
1573.65
$51,000.00
$68,525.00
$38,425.00
$59,750.00
$51,350.00
$40,150.00
$39,750.00
$65,250.00
$45,000.00
$42,450.00
$58,550.00
$58,000.00
$67,700.00
$48,800.00
$38,500.00
$57,525.00
$45,250.00
1530
2055.75
1152.75
1792.5
1540.5
1204.5
1192.5
1957.5
1350
1273.5
1756.5
1740
2031
1464
1155
1725.75
1357.5
10/8/2015
10/8/2015
110
111
112
114
115
116
118
119
121
124
125
126
127
EmpID
101
102
103
104
105
106
108
129
130
133
134
135
137
138
139
140
LastName
Ammons
Irving
Prescott
Vanderhoff
Gadeau
Wendt
Holmes
Byrnes
Bannerman
Blanca
Kaiser
O'Callaghan
Workman
Ishimoto
Larsen
Ochoa
Silvestri
Tapparo
Vincent
Ziegler
Alvarado
Curis
Dupree
Farrell
Griswold
Jacobsen
Masui
Prentiss
Schreiber
FirstName
Joseph
Walter
Francine
Mary
Corey
Stephanie
Nathan
Thomas
Ray
Noreen
Blaine
Sean
Silas
Glenn
Lucinda
Patricia
Antonio
Debra
Michelle
Kurt
Shilo
Norman
Brett
Sally
Dorothy
Leslie
Susan
Jerry
Kathleen
AnnualSalary Salary&Pension
$52,350.00
53920.5
$50,750.00
$52,500.00
$59,750.00
$60,150.00
52272.5
54075
61542.5
61954.5
$42,000.00
$53,350.00
$42,500.00
$32,600.00
$38,750.00
43260
54950.5
43775
33578
39912.5
66435
54028.65
52530
$52,455.00
$51,000.00
$68,525.00
$38,425.00
$59,750.00
$51,350.00
$40,150.00
$39,750.00
$65,250.00
70580.75
39577.75
61542.5
52890.5
41354.5
40942.5
67207.5
$45,000.00
$42,450.00
$58,550.00
$58,000.00
$67,700.00
$48,800.00
$38,500.00
$57,525.00
$45,250.00
46350
43723.5
60306.5
59740
69731
50264
39655
59250.75
46607.5
Salary&PensionQuery
UnitsOrderedTotalQuery
Two-person tent
Product
HT waterproof hiking boots, MS9
HT waterproof hiking boots, MS11
Polar backpack, 250RW
HT waterproof hiking boots, MS12
Two-person dome tent
Polar backpack, 150RW
Gordon wool ski hat, XXL
Gordon wool ski hat, XL
Shursite portable camp light
Lantern hanger
Tech-lite ski hat, L
Tech-lite ski hat, M
Lite-tech ski gloves, WS
Lite-tech ski gloves, WM
Lite-tech ski gloves, ML
Gordon wool ski hat, L
Shursite angle-head flashlight
Cascade R4 jacket, MXL
Multi-function compass
Ten-piece hiker cookware
Eight-piece stainless steel cookware
Deluxe map compass
SL 20-degrees synthetic sleeping bag, re 1024
SL 20-degrees synthetic sleeping bag, bla1025
Cascade R4 jacket, WM 1026
SL 15-degrees synthetic sleeping bag, re 1027
Cascade R4 jacket, ML
Cascade R4 jacket, WXL
HT waterproof hiking boots, WS8
HT waterproof hiking boots, WS7
Binoculars, 8 x 42
Thermaline roll-top table
HT waterproof hiking boots, WS9
HT waterproof hiking boots, WS11
Thermaline sleeping pad
1016
1017
1018
1019
1020
1021
1022
1023
1028
1029
1030
1031
1032
1033
1034
1035
1036
1008
1009
1010
1011
1012
1013
1014
1015
OrderID
1001
1002
1003
1004
1005
1006
1007
UnitsOrdered Amount Total
10 $1,288.50 $12,885.00
10 $887.90
10 $887.90
$8,879.00
$8,879.00
15 $2,397.75 $35,966.25
10 $887.90
$8,879.00
15 $2,999.85 $44,997.75
10 $1,495.00 $14,950.00
20 $145.80
$2,916.00
$4,500.00
$1,995.00
$672.75
Page 1
25 $180.00
10 $199.50
15 $44.85
25 $162.25
15 $97.35
20 $199.00
20 $199.00
10 $129.50
$4,056.25
$1,460.25
$3,980.00
$3,980.00
25 $173.75
15 $104.25
$1,295.00
$4,343.75
$1,563.75
10 $1,285.00 $12,850.00
10 $45.95
5 $124.25
5 $99.75
5 $129.75
$459.50
$621.25
$498.75
$648.75
10 $1,199.50 $11,995.00
10 $1,137.50 $11,375.00
5 $599.50
$2,997.50
15 $1,945.25 $29,178.75
10 $1,285.00 $12,850.00
5 $599.50
10 $752.90
10 $752.90
$2,997.50
$7,529.00
$7,529.00
5 $2,145.00 $10,725.00
5 $196.25
10 $752.90
8 $602.32
20 $397.00
$981.25
$7,529.00
$4,818.56
$7,940.00
UnitsOrderedTotalQuery
10/8/2015
Page 1
80
Access Level 1
■
Unit 1
Page 1
Page 1
Project 2
Create Aggregate Functions, Crosstab, Find Duplicates, and Find Unmatched Queries
Project 2a
AmountsQuery
SumOfAmount
$26,530.27
AvgOfAmount
$736.95
AmountsQuery
MaxOfAmount
$2,999.85
MinOfAmount
$44.85
CountOfAmount
36
ClaimAmountsQuery
10/8/2015
SumOfAmountOfClaim
$38,711.95
AvgOfAmountOfClaim
$2,037.47
ClaimAmountsQuery
MaxOfAmountOfClaim
$5,230.00
MinOfAmountOfClaim
$535.00
Project 2b
SumAvgClaimAmountsQuery
ClientID
1331
1574
4300
4567
4868
4875
5982
6478
7335
10/8/2015
8854
9383
9775
9879
SumOfAmountOfClaim
$1,797.00
$2,696.25
$10,088.30
$1,840.00
$2,675.00
$875.00
$3,250.50
$925.75
$834.95
$2,830.50
$3,100.50
$1,770.00
$4,500.00
$1,528.20
AvgOfAmountOfClaim
$1,797.00
$1,348.13
$5,044.15
$1,840.00
$2,675.00
$875.00
$3,250.50
$925.75
$834.95
$2,830.50
$1,550.25
$885.00
$4,500.00
$764.10
SumAvgClaimAmountsQuery
10/8/2015
SupplierAmountsQuery
SumOfAmount
$348.60
$224.00
$593.25
$5,524.72
$2,145.00
$3,892.75
$4,282.25
$3,769.00
$1,286.65
$175.70
$4,288.35
AvgOfAmount
$116.20 10
SupplierID
$112.00 15
$296.63 25
$789.25 31
$2,145.00 35
$1,946.38 42
$1,427.42 54
$942.25 60
$160.83 68
$87.85 84
$2,144.18 99
SupplierName
Hopewell, Inc.
Bayside Supplies
Langley Corporation
Sound Supplies
Emerald City Products
Fraser Valley Products
Manning, Inc.
Cascade Gear
Freedom Corporation
Macadam, Inc.
KL Distributions
SupplierAmountsQuery
Project 2c
OrdersBySupplierByProductQuery
SupplierName
Bayside Supplies
Cascade Gear
Emerald City Products
Fraser Valley Products
Freedom Corporation
Hopewell, Inc.
KL Distributions
Langley Corporation
Macadam, Inc.
Manning, Inc.
Sound Supplies
$224.00
$3,769.00
$2,145.00
$3,892.75
$1,286.65
$348.60
$4,288.35
$593.25
$175.70
$4,282.25
$5,524.72
$2,145.00
$173.75
$1,285.00
$180.00
$1,285.00
$145.80
$599.50
10/8/2015
$99.75
10/8/2015
HT waterproof hiking boots, WS7 HT waterproof hiking boots, WS9
$129.75
OrdersBySupplierByProductQuery 10/8/2015
Page 1
$44.85
Page 1
$602.32
$45.95
$162.25
$97.35
$752.90
Page 1
Ten-piece hiker cookware
$124.25
$1,945.25
$196.25
$397.00
$2,999.85
$1,288.50
$1,137.50
$1,199.50
OrdersBySupplierByProductQuery
Page 1
ClaimsByClaimIDByClientIDQuery
4567 ClaimID
102394
104366
121039
136695
147851
147858
153001
158954
158962
174223
174589
178545
198745
200147
210369
211458
241485
247823
248210
$1,235.00
$834.95
$5,230.00
$1,840.00
$3,250.50
$875.00
$535.00
$1,050.75
$2,830.50
$950.50
$752.45
$4,858.30
$1,797.00
$925.75
$2,675.00
$1,645.50
$4,500.00
$775.75
$2,150.00
$1,797.00
1574
$1,050.75
$1,645.50
4300
$5,230.00
$4,858.30
ClaimsByClaimIDByClientIDQuery
$1,840.00
4868
$2,675.00
Page 2
4875
$875.00
10/8/2015
5982
Page 3
6478
$3,250.50
$925.75
7335
$834.95
8223
ClaimsByClaimIDByClientIDQuery
8854 9383
$1,235.00
9775
$950.50
$2,150.00
$535.00
9879
$752.45
$4,500.00
$775.75
10/8/2015
10/8/2015
Project 2d
DuplicateSuppliersQuery 10/8/2015
SupplierName SupplierID
Langley Corporation 25
Langley Corporation 29
StreetAddress
805 First Avenue Burnaby
1248 Larson Avenue Burnaby
DuplicateSuppliersQuery
Prov/State PostalCode
BC V3J 1C9
BC V5V 9K2
EmailAddress [email protected]
Telephone
(604) 555-1200
(604) 555-1200
Page 2
Chapter 3
■
Performing Queries
81
Page 1
Project 2e
SupplierOrdersCountQuery
SupplierName Field
Bayside Supplies
Cascade Gear
Fraser Valley Products
Freedom Corporation
Hopewell, Inc.
KL Distributions
Langley Corporation
Macadam, Inc.
Manning, Inc.
Sound Supplies
NumberOfDups
2
2
3
2
3
7
2
8
2
4
SupplierOrdersCountQuery
10/8/2015
Project 2f
Products Without Matching Orders
100-01
100-03
100-04
101-S1B
101-S1R
101-S2B
155-30
155-45
155-55
200-CW
210-XL
250-M
250-XXL
255-L
299-M1
299-M4
651-1
652-2
804-50
804-60
897-L
897-W
901-S
917-S
ProductID
558-C
559-B
570-TL
580-TL
602-XT
602-XX
648-2
Product
ICE snow goggles, clear
ICE snow goggles, bronze
Thermaline light-weight cot
Thermaline camp seat
Binoculars, 10.5 x 45
Binoculars, 10 x 50
Three-person dome tent
K-2 one-person tent
K-2 two-person tent
AG freestyle snowboard, X50
AG freestyle snowboard, X60
Lang blunt snowboard
Lang blunt snowboard, wide
Solar battery pack
Silo portable power pack
Wrist compass
Lenspro plastic compass
Lenspro metal compass
SL 0-degrees down sleeping bag, black
Shursite aluminum flashlight
Shursite propane lantern
Shursite waterproof headlamp
Four-piece titanium cookware
Tech-lite ski hat, XL
Cascade R4 jacket, MM
Cascade R4 jacket, MXXL
Cascade R4 jacket, WL
HT waterproof hiking boots, MS13
HT waterproof hiking boots, MS10
68
60
60
60
10
10
10
15
31
31
70
70
70
70
35
99
99
99
38
38
84
84
68
25
25
35
SupplierID UnitsInStock
68 18
22
12
7
5
8
8
12
5
7
84
54
SL 0-degrees down sleeping bag, red 54
SL 15-degrees synthetic sleeping bag, blac 54
12
7
6
22
16
17
21
8
6
8
6
5
7
8
12
6
8
4
16
8
8
UnitsOnOrder
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10
10
0
5
20
5
5
5
15
15
5
10
10
5
5
15
ReorderLevel
15
20
5
10
4
5
10
15
10
7
3
10
10
10
5
Products Without Matching Orders
Page 1
10/8/2015
Project
1
Design Queries
8 Parts
You will design and run a number of queries including queries with fields from one table and queries with fields from more than one table. You will also use the
Simple Query Wizard to design queries.
Extracting Data with Queries
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
Being able to extract (pull out) specific data from a table is one of the most important functions of a database. extracting data in Access is referred to as performing a query. The word query means “question” and to perform a query means to ask a question. Access provides several methods for performing a query.
You can design your own query, use a simple query wizard, or use complex query wizards. In this chapter, you will learn to design your own query; use the Simple
Query Wizard; create a calculated field; use aggregate functions in a query; and use the Crosstab, Find Duplicates, and Unmatched Query wizards.
the first step in designing a query is to choose the fields that you want to display in the query results datasheet.
Query Design
Designing Queries
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
Designing a query consists of identifying the table from which you are gathering data, the field or fields from which the data will be drawn, and the criteria for selecting the data. To design a query and perform the query, open a database, click the CreATe tab, and then click the Query Design button in the Queries group.
This displays a query window in the work area and also displays the Show Table dialog box, as shown in Figure 3.1.
82
Access Level 1
■
Unit 1
Figure 3.1
Query Window with Show Table Dialog Box
Click the table name you want included in the query and then click the Add button.
Click the table name in the Show Table dialog box that you want included in the query and then click the Add button or double-click the desired table. This inserts a field list box for the table. Add any other tables required for the query.
When all tables have been added, click the Close button. In the query window, click the down-pointing arrow at the right of the first Field row field in the query design grid and then click the desired field from the drop-down list. Figure 3.2 displays a sample query window.
To establish a criterion, click inside the Criteria row field in the column containing the desired field name in the query design grid and then type the criterion. With the fields and criteria established, click the run button in the results group on the
QUerY TOOLS DeSIGN tab. Access searches the specified tables for records that match the criteria and then displays those records in the query results datasheet. If you plan to use the query in the future, save the query and name it. If you will not need the query again, close the query results datasheet without saving it.
To insert a field in the query design grid, click the down-pointing arrow at the right side of a Field row field and then click the desired field at the drop-down list. You can also double-click a field in a table field list box to insert the field in the first available Field row field in the query design grid. For example, suppose you want to find out how many purchase orders were issued on a specific date.
To do this, double-click PurchaseOrderID in the table field list box (which inserts
PurchaseOrderID
in the first Field row field in the query design grid) and then double-click OrderDate in the table field list box (which inserts OrderDate in the second Field row field in the query design grid). In this example, both fields are needed, so the purchase order ID is displayed along with the specific order date.
After inserting the fields, you insert the criterion. The criterion for this example is something like #1/15/2015#. After you insert the criterion, click the run button in the results group and the results of the query display in the query results datasheet.
Quick Steps
Design a Query
1. Click Create tab.
2. Click Query Design button.
3. at show table dialog box, click desired table, and then click add button.
4. add any additional tables.
5. in query design grid, click down-pointing arrow in Field row field and click desired field from drop-down list.
6. insert criterion.
7. Click run button.
8. save query.
Run
Chapter 3
■
Performing Queries
83
Figure 3.2
Query Window
table field list box query design grid
A third method for inserting a field in the query design grid is to drag a field from the table field list box to the desired field in the query design grid. To do this, position the mouse pointer on the desired field in the table field list box, hold down the left mouse button, drag to the desired Field row field in the query design grid, and then release the mouse button.
Quick Steps
Establish a Query
Criterion
1. at query window, click in desired Criteria row field in query design grid.
2. type criterion and then press enter.
3. Click run button.
insert fields in the Field row fields in the query design grid in the order in which you want the fields to display in the query results datasheet.
access inserts quotation marks around text criteria and pound symbols around date criteria.
establishing Query Criteria
Performing a query does not require specific criteria to be established. In the example described on the previous page, if the criterion for the date was not included, the query would return all purchase order numbers with the dates.
(Return is the term used for the results of the query.) While this information may be helpful, you could easily find this information in the table. The value of performing a query is to extract specific information from a table. To do this, you must insert a criterion like the one described in the example.
Access makes writing a criterion fairly simple by inserting the necessary symbols in the criterion. If you type a city name, such as Indianapolis, in the
Criteria
row field and then press enter, Access changes the criterion to
"Indianapolis"
. The quotation marks are inserted by Access and are necessary for the query to run properly. You can either let Access put the proper symbols in the
Criteria
row field, or you can type the criterion with the symbols. Table 3.1 shows some examples of criteria, including what is typed and what is returned.
In the criteria examples, the asterisk is used as a so-called wildcard character, or a symbol that can be used to indicate any character. This is consistent with many other software applications. Two of the criteria examples in Table 3.1 use less-than and greater-than symbols. You can use these symbols for fields containing numbers, values, dates, amounts, and so forth. In the next several projects, you will design queries to extract specific information from different tables in databases.
84
Access Level 1
■
Unit 1
Table 3.1
Criteria Examples
Typing This Criterion
"Smith"
"Smith" Or "Larson"
Not "Smith"
"s*"
"*s"
"[A-D]*"
#01/01/2015#
<#04/01/2015#
>#04/01/2015#
Between #01/01/2015#
And #03/31/2015#
Returns This Result
Field value that matches Smith
Field value that matches either Smith or Larson
Field value that is not Smith (the opposite of “Smith”)
Field value that begins with S or s and ends in anything
Field value that begins with anything and ends in S or s
Field value that begins with A, B, C, or D and ends in anything
Field value that matches the date 01/01/2015
Field value that is less than (before) 04/01/2015
Field value that is greater than (after) 04/01/2015
Field value that is between 01/01/2015 and 03/31/2015
Project 1a
Performing Queries on Tables
Part 1 of 8
1. Open AL1-C3-Dearborn.accdb from the AL1C3 folder on your storage medium and enable the contents.
2. Create the following relationships and enforce referential integrity (and cascade fields and records) for each relationship: a. Create a one-to-many relationship with the ClientID field in the Clients field list box the
“one” and the ClientID field in the Sales field list box the “many.” b. Create a one-to-one relationship with the RepID field in the Representatives field list box the “one” and the RepID field in the Benefits field list box the “one.” c. Create a one-to-many relationship with the RepID field in the Representatives field list box the “one” and the RepID field in the Clients field list box the “many.” d. Create a one-to-many relationship with the QuotaID field in the Quotas field list box the
“one” and the QuotaID field in the Representatives field list box the “many.”
3. Click the Save button on the Quick Access toolbar.
4. Print the relationships by completing the following steps: a. Click the relationship report button in the Tools group on the reLATIONSHIP
TOOLS DeSIGN tab.
b. At the relationship report window, click the Landscape button in the Page Layout group on the PrINT PreVIeW tab.
c. Click the Print button that displays at the left side of the PrINT PreVIeW tab.
d. At the Print dialog box, click OK.
5. Close the relationship report window without saving the report.
6. Close the relationships window.
Chapter 3
■
Performing Queries
85
7. extract records of those clients located in Indianapolis by completing the following steps: a. Click the CreATe tab.
b. Click the Query Design button in the Queries group.
c. At the Show Table dialog box with the Tables tab selected (see Figure 3.1), click Clients
Step
7a
Step
7b
in the list box, click the Add button, and then click the Close button.
d. Insert fields from the Clients field list box to the Field row fields in the query design grid by completing the following steps:
1) Click the down-pointing arrow located at the right of the first Field row field in the query design grid and then click Client in the drop-down list.
2) Click inside the next Field row field (to the right of
Client
) in the query design grid, click the down-pointing
Step
7d1
arrow, and then click StreetAddress in the drop-down list.
3) Click inside the next Field row field (to the right of
StreetAddress
), click the down-pointing arrow, and then click City in the drop-down list.
4) Click inside the next Field row field (to the right of
City
), click the down-pointing arrow, and then click State in the drop-down list.
5) Click inside the next Field row field (to the right of State), click the down-pointing arrow, and then select ZipCode in the drop-down list.
Step
7d2
Step
7d3
Step
7d4
Step
7d5
86
Access Level 1
■
Unit 1
e. Insert the criterion text telling Access to display only those suppliers located in
Indianapolis by completing the following steps:
1) Click in the Criteria row field in the
City
column in the query design grid.
Step
7e2
(This positions the insertion point in the field.)
2) Type
Indianapolis
and then press enter. (This changes the criterion to
“Indianapolis”.) f. return the results of the query by clicking the run button in the results group on the QUerY TOOLS
DeSIGN tab. (This displays the results in the query results datasheet.) g. Save the results of the query by completing the following steps:
1) Click the Save button on the
Quick Access toolbar.
Step
7f
2) At the Save As dialog box, type
ClientsIndianapolisQuery
and then press enter or click OK. (See Project 1a query results on page 78.) h. Print the query results datasheet by clicking the FILe tab, clicking the Print option, and then clicking the Quick Print button.
i. Close ClientsIndianapolisQuery.
8. extract those records with quota identification numbers greater than 2 by completing the following steps: a. Click the CreATe tab and then click the Query Design button in the Queries group.
b. Double-click Representatives in the Show Table dialog box and then click the Close button.
c. In the query window, double-click RepName. (This inserts the field in the first Field row field in the query design grid.) d. Double-click QuotaID. (This inserts the field in the second Field row field in the query design grid.) e. Insert the query criterion by completing the following steps:
1) Click in the Criteria row field in the QuotaID column in the query design grid.
2) Type
>2
and then press enter. (Access will automatically insert quotation marks around 2 since the data type for the field is identified as
Short Text
[rather than Number].) f. return the results of the query by clicking the run button in the results group.
g. Save the query and name it QuotaIDGreaterThanTwoQuery.
(See Project 1a query results on page 78.) h. Print and then close the query.
9. extract those sales greater than $99,999 by completing the following steps:
Step
8e2
a. Click the CreATe tab and then click the Query Design button.
b. Double-click Sales in the Show Table dialog box and then click the Close button.
c. At the query window, double-click ClientID. (This inserts the field in the first Field row field in the query design grid.) d. Insert the Sales field in the second Field row field.
Chapter 3
■
Performing Queries
87
e. Insert the query criterion by completing the following steps:
1) Click in the Criteria row field in the Sales column in the query design grid.
2) Type
>99999
and then press enter. (Access will not insert quotation marks around 99999 since the field is identified as Currency.) f. return the results of the query by clicking the run
Step
9e2
button in the results group.
g. Save the query and name it SalesOver$99999Query. (See Project 1a query results on page 78.) h. Print and then close the query.
10. extract records of those representatives with a telephone number that begins with the 765 area code by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Representatives in the Show Table dialog box and then click the Close button.
c. Insert the RepName field in the first Field row field.
d. Insert the Telephone field in the second Field row field.
e. Insert the query criterion by completing the following steps:
1) Click in the Criteria row field in the Telephone column.
2) Type
"(765*"
and then press enter. (You need to type the quotation marks in this criterion because the criterion contains a left parenthesis.) f. return the results of the query by clicking the run button in the results group.
g. Save the query and name it RepsWith765AreaCodeQuery. (See Project 1a query results on page 78.) h. Print and then close the query.
Step
10e2
In Project 1a, you performed several queries on specific tables. You can also perform queries on fields from more than one table. In Project 1b, you will perform queries on related tables.
When completing steps in Project 1b, you will be instructed to open
AL1-C3-CopperState.accdb. Two of the tables in the database contain yes/no check boxes. When designing a query, you can extract records that contain a check mark or records that do not contain a check mark. If you want to extract records that contain a check mark, click in the Criteria row field in the desired column in the query design grid, type a 1, and then press enter. When you press the enter key, Access changes the 1 to True. If you want to extract records that do not contain a check mark, type 0 in the Criteria row field and then press enter. Access changes the 0 to False.
You can use the Zoom box when entering a criterion in a query to provide a larger area for typing. To display the Zoom box, press Shift + F2 or right-click in the desired Criteria row field and then click Zoom at the shortcut menu. Type the desired criterion in the Zoom box and then click OK.
88
Access Level 1
■
Unit 1
Project 1b
Performing Queries on Related Tables
Part 2 of 8
1. With AL1-C3-Dearborn.accdb open, extract information on representatives hired between
March 2011 and November 2011 and include the representatives’ names by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Representatives in the Show
Step
1d
Table dialog box.
c. Double-click Benefits in the Show Table dialog box and then click the Close button.
d. At the query window, double-click RepName in the Representatives field list box.
e. Double-click HireDate in the Benefits field list box.
f. Insert the query criterion in the Zoom box by completing the following steps:
1) Click in the Criteria row field in the HireDate column.
2) Press Shift + F2 to display the Zoom box.
3) Type
Between 3/1/2011 And 11/30/2011
.
Step
1f3
(Make sure you type zeros and not capital Os.)
4) Click OK.
g. return the results of the query by clicking the run button in the results group.
h. Save the query and name it
MarToNov2011HiresQuery
.
(See Project 1b query results
Step
1f4
on page 78.) i. Print and then close the query.
2. extract records of those representatives who were hired in 2012 by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Representatives in the Show Table dialog box.
c. Double-click Benefits in the Show Table dialog box and then click the Close button.
d. At the query window, double-click the RepID field in the Representatives field list box.
e. Double-click RepName in the Representatives field list box.
f. Double-click HireDate in the Benefits field list box.
g. Insert the query criterion by completing the following steps:
1) Click in the Criteria row field in the
HireDate
column.
2) Type
*2012
and then press enter.
h. return the results of the query by clicking the run button in the results group.
i. Save the query and name it RepsHiredIn2012Query.
(See Project 1b query results on page 78.) j. Print and then close the query.
Step
2g2
Chapter 3
■
Performing Queries
89
3. Suppose you need to determine sales for a company but you can only remember that the company name begins with Blue. Create a query that finds the company and identifies the sales by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Clients in the Show Table dialog box.
c. Double-click Sales in the Show Table dialog box and then click the Close button.
d. At the query window, insert the ClientID field from the Clients field list box in the first
Field
row field in the query design grid.
e. Insert the Client field from the Clients field list box in the second Field row field.
f. Insert the Sales field from the Sales field list box in the third
Field
row field.
g. Insert the query criterion by completing the following steps:
Step
3g2
1) Click in the Criteria row field in the Client column.
2) Type
Blue*
and then press enter.
h. return the results of the query by clicking the run button in the results group.
i. Save the query and name it
BlueRidgeSalesQuery
. (See Project
1b query results on page 78.) j. Print and then close the query.
4. Close AL1-C3-Dearborn.accdb.
5. Display the Open dialog box with the AL1C3 folder on your storage medium active.
6. Open AL1-C3-PacTrek.accdb and enable the contents.
7. extract information on products ordered between February 1, 2015, and February 28,
2015, by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Products in the Show Table dialog box.
c. Double-click Orders in the Show Table dialog box and then click the Close button.
d. At the query window, insert the ProductID field from the Products field list box in the first
Field
row field.
e. Insert the Product field from the Products field list box in the second Field row field.
f. Insert the OrderDate field from the Orders field list box in the third Field row field.
g. Insert the query criterion by completing the following steps:
1) Click in the Criteria row field in the
OrderDate
column.
2) Type
Between 2/1/2015 And
2/28/2015
and then press enter. (Make sure you type zeros and not capital Os.) h. return the results of the query by clicking the run button in the results group.
i. Save the query and name it Feb1-
28OrdersQuery
. (See Project 1b query results on page 78.)
Step
7g2
j. Print and then close the query.
8. Close AL1-C3-PacTrek.accdb.
9. Open AL1-C3-CopperState.accdb and enable the contents.
10. Display the relationships window and create the following additional relationships
(enforce referential integrity and cascade fields and records): a. Create a one-to-many relationship with the AgentID field in the Agents field list box the
“one” and the AgentID field in the Assignments field list box the “many.”
90
Access Level 1
■
Unit 1
b. Create a one-to-many relationship with the OfficeID field in the Offices field list box the
“one” and the OfficeID field in the Assignments field list box the “many.” c. Create a one-to-many relationship with the OfficeID field in the Offices field list box the
“one” and the OfficeID field in the Agents field list box the “many.”
11. Save and then print the relationships.
12. Close the relationship report without saving it and then close the relationships window.
13. extract records of clients that have uninsured motorist coverage by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Clients in the Show Table dialog box.
c. Double-click Coverage in the Show Table dialog box and then click the Close button.
d. At the query window, insert the ClientID field from the Clients field list box in the first Field row field.
e. Insert the FirstName field from the Clients field list box in the second Field row field.
f. Insert the LastName field from the Clients field list box in the third Field row field.
g. Insert the UninsMotorist field from the Coverage field list box in the fourth Field row field.
(You may need to scroll down the Coverage field list box to display the UninsMotorist field.) h. Insert the query criterion by clicking in the Criteria row field in the UninsMotorist column, typing
Step
13h
1
, and then pressing the enter key.
(Access changes the 1 to True.) i. Click the run button in the results group.
j. Save the query and name it UninsMotoristCoverageQuery. (See Project 1b query results on page 78.) k. Print and then close the query.
14. extract records of claims in January over $500 by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Clients in the Show Table dialog box.
c. Double-click Claims in the Show Table dialog box and then click the Close button.
d. At the query window, insert the ClientID field from the Clients field list box in the first Field row field.
e. Insert the FirstName field from the Clients field list box in the second Field row field.
f. Insert the LastName field from the Clients field list box in the third Field row field.
g. Insert the ClaimID field from the Claims field list box in the fourth Field row field.
h. Insert the DateOfClaim field from the Claims field list box in the fifth Field row field.
i. Insert the AmountOfClaim field from the Claims field list box in the sixth Field row field.
j. Click in the Criteria row field in the DateOfClaim column, type
Between 1/1/2015 And
1/31/2015
, and then press enter.
k. With the insertion point positioned in the Criteria row field in the AmountOfClaim column, type
>500
and then press enter.
l. Click the run button in the results group.
m. Save the query and name it JanClaimsOver$500Query.
(See Project 1b query results on page 78.) n. Print and then close the query.
Step
14j
Step
14k
Chapter 3
■
Performing Queries
91
Quick Steps
Sort Fields in a Query
1. at query window, click in Sort row field in query design grid.
2. Click down arrow in
Sort row field.
3. Click Ascending or
Descending.
sorting and showing or Hiding Fields in a Query
When designing a query, you can specify the sort order of a field or fields. Click inside one of the columns in the Sort row field and a down-pointing arrow displays at the right of the field. Click this down-pointing arrow and a drop-down list displays with the choices Ascending, Descending, and (not sorted). Click Ascending to sort from lowest to highest or click Descending to sort from highest to lowest. You can hide specific fields in the query result by removing the check mark from the check box in the Show row in the design grid for the field you do not want to show.
Insert Columns
Delete Columns
arranging Fields in a Query
With buttons in the Query Setup group on the QUerY DeSIGN TOOLS tab, you can insert a new field column in the query design grid and delete a field column from the query design grid. To insert a field column, click in a field in the column you want to display immediately right of the new column and then click the Insert Columns button in the Query Setup group on the QUerY
DeSIGN TOOLS tab. To remove a column, click in a field in the column you want to delete and then click the Delete Columns button in the Query Setup group. Complete similar steps to insert or delete a row in the query design grid.
You can also rearrange columns in the query design grid by selecting the desired field column and then dragging the column to the desired position. To select a column in the query design grid, position the mouse pointer at the top of the column until the pointer turns into a small, black, down-pointing arrow and then click the left mouse button. Position the mouse pointer toward the top of the selected column until the mouse displays as a pointer, hold down the left mouse button, drag to the desired position in the design grid, and then release the mouse button. As you drag the column, a thick, black, vertical line displays identifying the location where the column will be inserted.
Project 1c
Performing Queries on Related Tables and Sorting in Field Values
Part 3 of 8
1. With AL1-C3-CopperState.accdb open, extract information on clients with agents from the West Bell road Glendale office and sort the information alphabetically by client last name by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Assignments in the Show Table dialog box.
c. Double-click Clients in the Show Table dialog box and then click the Close button.
d. At the query window, insert the OfficeID field from the Assignments field list box in the first Field row field.
e. Insert the AgentID field from the Assignments field list box in the second Field row field.
f. Insert the FirstName field from the Clients field list box in the third Field row field.
g. Insert the LastName field from the Clients field list box in the fourth Field row field.
92
Access Level 1
■
Unit 1
h. Click in the Criteria row field in the OfficeID column, type
GW
, and then press enter.
i. Sort the LastName field in ascending alphabetical order (A–Z) by completing the following steps:
1) Click in the Sort row field in the LastName column. (This causes a down-pointing arrow to display at the right side of the field.)
2) Click the down-pointing arrow at the right side of the Sort row field and then click
Ascending
.
j. Specify that you do not want the AgentID field to show in the query results by clicking in the check box in the Show row field in the AgentID column to remove the check mark.
Step
1h
Step
1j
Step
1i2
k. Click the run button in the results group. l. Save the query and name it GWClientsQuery. (See Project 1c query results on page 79.)
m. Print and then close the query.
2. Close AL1-C3-CopperState.accdb.
3. Open AL1-C3-PacTrek.accdb.
4. extract information on orders less than $1,500 by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Products in the Show Table dialog box.
c. Double-click Orders in the Show Table dialog box and then click the Close button.
d. At the query window, insert the ProductID field from the Products field list box in the first
Field
row field.
e. Insert the SupplierID field from the Products field list box in the second Field row field.
f. Insert the UnitsOrdered field from the Orders field list box in the third Field row field.
g. Insert the Amount field from the Orders field list box in the fourth Field row field.
h. Insert the query criterion by completing the following steps:
1) Click in the Criteria row field in the Amount column.
2) Type
<1500
and then press enter. (Make sure you type zeros and not capital Os.) i. Sort the Amount field values from highest to lowest by completing the following steps:
1) Click in the Sort row field in the Amount column. (This causes a downpointing arrow to display at the right side of the field.)
2) Click the down-pointing arrow at the right side of the Sort field and then click Descending.
j. return the results of the query by clicking the run button in the results group.
k. Save the query and name it OrdersLessThan$1500Query.
(See Project 1c query results on page 79.) l. Print and then close the query.
5. Close AL1-C3-PacTrek.accdb.
6. Open AL1-C3-Dearborn.accdb.
7. Design a query by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Representatives in the Show Table dialog box.
Step
4i2
Step
4h2
Chapter 3
■
Performing Queries
93
c. Double-click Clients in the Show Table dialog box.
d. Double-click Sales in the Show Table dialog box and then click the Close button.
e. At the query window, insert the RepID field from the Representatives field list box in the first Field row field.
f. Insert the RepName field from the Representatives field list box in the second Field row field.
g. Insert the ClientID field from the Clients field list box in the third Field row field.
h. Insert the Sales field from the Sales field list box in the fourth Field row field.
8. Move the RepName field by completing the following steps: a. Position the mouse pointer at the top of the
RepName
column until the pointer turns into a small, black, down-pointing arrow and then click the left mouse button. (This selects the entire column.) b. Position the mouse pointer toward the top of the selected column until the pointer turns
Step
8a
into a white arrow.
c. Hold down the left mouse button; drag to the right until a thick, black horizontal line displays between the ClientID column and the Sales column; and then release
Step
8c
the mouse button.
9. Delete the RepID field by clicking in a field in the column and then clicking the
Delete Columns button in the Query Setup group.
10. Insert a new field column and insert a new field in the column by completing the following steps: a. Click in the Sales field and then click the Insert
Columns button in the Query Setup group.
b. Click the down-pointing arrow at the right
Step
10b
side of the new field and then click
Clients.Client
at the drop-down list.
11. Hide the ClientID field so it does not display in the query results by clicking the Show check box in the ClientID column to remove the check mark.
12. Insert the query criterion that extracts information on sales over $100,000 by completing the following steps: a. Click in the Criteria row field in the Sales column.
b. Type >100000 and then press enter. (Make sure you type zeros and not capital Os.)
13. Sort the Sales field values from highest to lowest by completing the following steps: a. Click in the Sort row field in the Sales column.
b. Click the down-pointing arrow at the right side of the Sort row field and then click Descending.
14. return the results of the query by clicking the run button in the results group.
15. Save the query and name it SalesMoreThan$100000Query. (See Project 1c query results on page 79.)
16. Print and then close the query.
94
Access Level 1
■
Unit 1
Modifying a Query
You can modify a saved query and use it for a new purpose. For example, suppose that after designing the query that displays sales of more than $100,000, you decide that you want to find sales that are less than $100,000. rather than design a new query, open the existing query, make any needed changes, and then run the query.
To modify an existing query, double-click the query in the Navigation pane.
(This displays the query in Datasheet view.) Click the View button to display the query in Design view. You can also open a query in Design view by right-clicking the query in the Navigation pane and then clicking Design View at the shortcut menu. Make the desired changes and then click the run button in the results group. Click the Save button on the Quick Access toolbar to save the query with the same name. If you want to save the query with a new name, click the FILe tab, click the Save As option, click the Save Object As option, and then click the Save As button. At the Save As dialog box, type a name for the query and then press enter.
If your database contains a number of queries, you can group and display them in the Navigation pane. To do this, click the down-pointing arrow in the
Navigation pane menu bar and then click Object Type at the drop-down list. This displays objects grouped in categories, such as Tables and Queries.
renaming and Deleting a Query
If you modify a query, you may want to rename it. To do this, right-click the query name in the Navigation pane, click Rename at the shortcut menu, type the new name, and then press enter. If you no longer need the query in the database, delete it by clicking the query name in the Navigation pane, clicking the Delete button in the records group on the HOMe tab, and then clicking the Yes button at the message asking if you want to permanently delete the query. Another method is to right-click the query in the Navigation pane, click Delete at the shortcut menu, and then click the Yes at the message. If you are deleting a query from your computer’s hard drive, the message asking if you want to permanently delete the query will not display. This is because Access automatically sends the deleted query to the recycle Bin, where it can be retrieved if necessary.
Quick Steps
Modify a Query
1. Double-click query in navigation pane.
2. Click View button.
3. Make desired changes to query.
4. Click run button.
5. Click save button.
save time designing a new query by modifying an existing query.
Project 1d
Modifying Queries
Part 4 of 8
1. With AL1-C3-Dearborn.accdb open, find sales less than $100,000 by completing the following steps: a. Double-click SalesMoreThan$100000Query in the Queries group in the Navigation pane.
b. Click the View button in the Views group to switch to Design view.
c. Click in the Criteria row field containing the text >100000 and then edit the text so it displays as <100000.
Step
1c
d. Click the run button in the results group.
Chapter 3
■
Performing Queries
95
2. Save the query with a new name by completing the following steps: a. Click the FILe tab, click the Save As option, click the Save Object As option, and then click the Save
As button.
b. At the Save As dialog box, type
SalesLessThan$100000Query
and then press enter. (See Project 1d query results on page 79.) c. Print and then close the query.
3. Modify an existing query and find employees with three weeks of vacation by completing the following steps: a. right-click MarToNov2011HiresQuery in the
Queries group in the Navigation pane and then click Design View at the shortcut menu.
b. Click in the Field row field containing the text HireDate.
Step
2b
c. Click the down-pointing arrow that displays at the right side of the field and then click
Vacation
at the drop-down list.
d. Select the current text in the Criteria row field in the Vacation column, type
3 weeks
, and then press enter.
e. Click the run button in the results group.
f. Save and then close the query.
Step
3d
4. rename the query by completing the following steps: a. right-click MarToNov2011HiresQuery in the Navigation pane and then click Rename at the shortcut menu.
b. Type
RepsWith3WeekVacationsQuery
and then press enter. (See Project 1d query results on page 79.) c. Open, print and then close the query.
5. Delete the SalesOver$99999Query by right-clicking the query name in the Navigation pane and then clicking Delete at the shortcut menu. If a message displays asking if you want to permanently delete the query, click Yes.
96
you can design a query that combines And and
Or statements.
Designing Queries with Or and And Criteria
The query design grid contains an or row that you can use to design a query that instructs Access to display records matching any of the criteria. Multiple criterion statements on different rows in a query become an Or statement, which means that any of the criterion can be met for a record to be displayed in the query results datasheet. For example, to display a list of employees with three weeks of vacation or four weeks of vacation, type 3 weeks in the Criteria row field for the
Vacation
column and then type 4 weeks in the field immediately below 3 weeks in the
or
row. Other examples include finding clients that live in Muncie or Lafayette and finding representatives with quotas of 1 or 2.
You can also select records by entering criteria statements into more than one Criteria field. Multiple criteria all entered in the same row become an And statement, for which each criterion must be met for Access to select the record. For example, you can search for clients in the Indianapolis area with sales greater than
$100,000.
Access Level 1
■
Unit 1
Project 1e
Designing Queries with Or and And Criteria
Part 5 of 8
1. With AL1-C3-Dearborn.accdb open, modify an existing query and find employees with three weeks or four weeks of vacation by completing the following steps: a. Double-click the RepsWith3WeekVacationsQuery.
b. Click the View button in the Views group to switch to Design view.
c. Click in the empty field below "3 weeks" in the or row, type
4 weeks
, and then press enter.
d. Click the run button in the results group.
2. Save the query with a new name by completing the following steps: a. Click the FILe tab, click the Save As option, click the Save Object As option, and then click the Save As button.
b. At the Save As dialog box, type
RepsWith3Or4WeekVacationsQuery
and then press enter. (See Project 1e query results on page 79.) c. Print and then close the query.
3. Design a query that finds records of clients in the Indianapolis area with sales over
Step
1c
$100,000 by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Clients in the Show Table dialog box.
c. Double-click Sales in the Show Table dialog box and then click the Close button.
d. At the query window, insert the Client field from the Clients field list box in the first Field row field.
e. Insert the City field from the Clients field list box in the second Field row field.
f. Insert the Sales field from the Sales field list box in the third Field row field.
g. Insert the query criteria by completing the following steps:
1) Click in the Criteria row field in the City column.
2) Type
Indianapolis
and then press enter.
3) With the insertion point positioned in the Criteria row field in the Sales column, type
>100000
and then press enter.
h. Click the run button in the
Step
3g2
Step
3g3
results group.
i. Save the query and name it SalesOver$100000IndianapolisQuery. (See Project 1e query results on page 79.) j. Print and then close the query.
4. Close AL1-C3-Dearborn.accdb.
5. Open AL1-C3-PacTrek.accdb.
6. Design a query that finds products available from supplier numbers 25, 31, and 42 by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Suppliers in the Show Table dialog box.
c. Double-click Products in the Show Table dialog box and then click the Close button.
d. At the query window, insert the SupplierID field from the Suppliers field list box in the first Field row field.
Chapter 3
■
Performing Queries
97
e. Insert the SupplierName field from the Suppliers field list box in the second Field row field.
f. Insert the Product field from the Products field list box in the third Field row field.
g. Insert the query criteria by completing the following steps:
1) Click in the Criteria row field in the SupplierID column.
2) Type
25
and then press the Down Arrow key on your keyboard. (This makes
Step
6g2
active the field below 25.)
3) Type
31
and then press the Down Arrow key on your keyboard. (This makes active the field below 31.)
4) Type
42
and then press enter.
h. Click the run button in the
Step
6g3
Step
6g4
results group.
i. Save the query and name it Suppliers25-31-42Query. (See Project 1e query results on page 79.) j. Print and then close the query.
7. Design a query that finds ski hats or gloves on order and the numbers ordered by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Orders in the Show Table dialog box.
c. Double-click Suppliers in the Show Table dialog box.
d. Double-click Products in the Show Table dialog box and then click the Close button.
e. At the query window, insert the OrderID field from the Orders field list box in the first Field row field.
f. Insert the SupplierName field from the Suppliers field list box in the second Field row field.
g. Insert the Product field from the Products field list box in the third Field row field.
h. Insert the UnitsOrdered field from the Orders field list box in the fourth Field row field.
i. Insert the query criteria by completing the following steps:
1) Click in the Criteria row field in the Product column.
2) Type
*ski hat*
and then press the Down Arrow key on your keyboard. (You need to type the asterisk before and after ski hat so the query will find any product that includes the words ski hat in the description, no matter what text comes before or after the words.)
Step
7i2
3) Type
*gloves*
and then press enter.
Step
7i3
j. Click the run button in the results group.
k. Save the query and name it SkiHatsGlovesOnOrderQuery. (See Project 1e query results on page 79.) l. Print and then close the query.
98
Access Level 1
■
Unit 1
8. Design a query that finds boots, sleeping bags, or backpacks and the suppliers that produce them by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Products in the Show Table dialog box.
c. Double-click Suppliers in the Show Table dialog box and then click the Close button.
d. At the query window, insert the ProductID field from the Products field list box in the first
Field
row field.
e. Insert the Product field from the Products field list box in the second Field row field.
f. Insert the SupplierName field from the Suppliers field list box in the third Field row field.
g. Insert the query criteria by completing the following steps:
1) Click in the Criteria row field in the Product column.
2) Type
*boots*
and then press the Down Arrow key on your keyboard.
3) Type
*sleeping bag*
and then press the Down Arrow key on your keyboard.
4) Type
*backpack*
and then press enter.
Step
8g2
Step
8g4
Step
8g3
h. Click the run button in the results group.
i. Save the query and name it BootsSleepingBagsBackpacksQuery. (See Project 1e query results on page 79.) j. Print and then close the query.
9. Close AL1-C3-PacTrek.accdb.
10. Open AL1-C3-CopperState.accdb.
11. Design a query that finds clients that have only liability auto coverage by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Clients in the Show Table dialog box.
c. Double-click Coverage in the Show Table dialog box and then click the Close button.
d. At the query window, insert the ClientID field from the Clients field list box in the first
Field
row field.
e. Insert the FirstName field from the Clients field list box in the second Field row field.
f. Insert the LastName field from the Clients field list box in the third Field row field.
g. Insert the Medical field from the Coverage field list box in the fourth Field row field.
h. Insert the Liability field from the Coverage field list box in the fifth Field row field.
i. Insert the Comprehensive field from the Coverage field list box in the sixth Field row field.
j. Insert the UninsMotorist field from the Coverage field list box in the seventh Field row field. (You may need to scroll down the Coverage field list box to display the
UninsMotorist
field.) k. Insert the Collision field from the Coverage field list box in the eighth Field row field.
(You may need to scroll down the Coverage field list box to display the Collision field.)
Chapter 3
■
Performing Queries
99
l. Insert the query criteria by completing the following steps:
1) Click in the Criteria row field in the Medical column, type
0
, and then press enter.
(Access changes the 0 to False.)
2) With the insertion point in the Liability column, type
1
and then press enter.
(Access changes the 1 to True.)
3) With the insertion point in the Comprehensive column, type
0
and then press enter.
4) With the insertion point in the UninsMotorist column, type
0
and then press enter.
5) With the insertion point in the Collision column, type
0
and then press enter.
Step
11l1
Step
11l2
Step
11l3
Step
11l4
Step
11l5
m. Click the run button in the results group.
n. Save the query and name it ClientsWithOnlyLiabilityQuery. (See Project 1e query results on page 79.) o. Print the query in landscape orientation.
p. Close the query.
12. Close AL1-C3-CopperState.accdb.
Query Wizard
Performing Queries with the Simple Query Wizard
■ ■ ■ ■
The Simple Query Wizard provided by Access guides you through the steps for preparing a query. To use this wizard, open the database, click the CreATe tab, and then click the Query Wizard button in the Queries group. At the New Query dialog box, make sure Simple Query Wizard is selected in the list box and then click the OK button. At the first Simple Query Wizard dialog box, shown in Figure 3.3, specify the table(s) in the Tables/Queries option box. After specifying the table(s), insert the fields you want included in the query in the Selected Fields list box and then click the
Next button.
Figure 3.3
First Simple Query Wizard Dialog Box
Specify the table(s) in the Tables/Queries option box.
Click the One Field button to insert the selected field in the Available Fields list box into the Selected Fields list box.
Click the All Fields button to insert all of the fields in the Available Fields list box into the Selected Fields list box.
Insert in the Selected Fields list box the fields you want included in the query.
100
Access Level 1
■
Unit 1
At the second Simple Query Wizard dialog box, specify whether you want a detail or summary query and then click the Next button. At the third (and last)
Simple Query Wizard dialog box, shown in Figure 3.4, type a name for the completed query or accept the name provided by the wizard. At this dialog box, you can also specify that you want to open the query to view the information or modify the query design. If you want to extract specific information, be sure to choose the Modify the query design option. After making any necessary changes, click the Finish button.
If you do not modify the query design in the last Simple Query Wizard dialog box, the query displays all records for the fields identified in the first Simple Query
Wizard dialog box. In Project 1f, you will perform a query without modifying the design, and in Project 1g, you will modify the query design.
Quick Steps
Create a Query with the Simple Query
Wizard
1. Click Create tab.
2. Click Query Wizard button.
3. Make sure Simple
Query Wizard is selected in list box and then click oK.
4. Follow query steps.
Figure 3.4
Last Simple Query Wizard Dialog Box
Type a name for the query in this text box or accept the name provided by the wizard.
Click this option if you want to modify the query design.
Project 1f
Performing Queries with the Simple Query Wizard
1. Open AL1-C3-Dearborn.accdb and then use the
Simple Query Wizard to create a query that displays client names along with sales by completing the following steps: a. Click the CreATe tab and then click the Query
Wizard button in the Queries group. b. At the New Query dialog box, make sure Simple Query
Wizard
is selected in the list box and then click OK.
c. At the first Simple Query Wizard dialog box, click the down-pointing arrow at the right of the Tables/
Queries
option box and then click Table: Clients.
Part 6 of 8
Step
1c
Chapter 3
■
Performing Queries
101
d. With ClientID selected in the Available Fields list box, click the One Field button
(the button containing the greater-than symbol, >). This inserts the ClientID field in the Selected Fields list box.
e. Click Client in the Available
Fields
list box and then click the One Field button.
f. Click the down-pointing arrow at the right of the
Tables/Queries
option box and then click Table: Sales.
g. Click Sales in the Available Fields list box and then click the One Field button.
h. Click the Next button.
i. At the second Simple Query Wizard dialog box, click the Next button.
j. At the last Simple Query Wizard dialog box, select the name in the
What title do you want for your query?
text box, type
ClientSalesQuery
, and then press enter.
Step
1f
Steps
1d-1e
Step
1j
Step
1g
Step
1h
k. When the results of the query display, print the results.
(See Project 1f query results on page 80.)
2. Close the query.
3. Close AL1-C3-Dearborn.accdb.
4. Open AL1-C3-PacTrek.accdb.
5. Create a query that displays the products on order, order amounts, and supplier names by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button.
b. At the New Query dialog box, make sure Simple Query Wizard is selected in the list box and then click OK.
102
Access Level 1
■
Unit 1
c. At the first Simple Query
Wizard dialog box, click the down-pointing arrow at the right side of the Tables/Queries option box and then click
Table: Suppliers
.
d. With SupplierID selected in the Available Fields list box, click the One Field button.
(This inserts the SupplierID field in the Selected Fields list box.) e. With SupplierName selected in the Available Fields list box, click the One Field button.
f. Click the down-pointing
Step
5c
arrow at the right of the Tables/Queries option box and then click Table: Orders.
g. Click ProductID in the Available Fields list box and then click the One Field button.
h. Click Amount in the Available Fields list box and then click the One Field button.
i. Click the Next button.
j. At the second Simple Query Wizard dialog box, click the Next button.
Steps
5d-5e
Steps
5g-5h
Step
5f
Step
5i
k. At the last Simple Query Wizard dialog box, select the text in the What title do you want
for your query?
text box, type
ProductOrderAmountsQuery
, and then press enter.
l. When the results of the query display, print the results. (See
Project 1f query results on page 80.)
m. Close the query.
Step
5k
Chapter 3
■
Performing Queries
103
To extract specific information when using the Simple Query Wizard, tell the wizard that you want to modify the query design. This displays the query window with the query design grid, where you can insert query criteria.
Project 1g
Performing and Modifying Queries with the Simple Query Wizard
Part 7 of 8
1. With AL1-C3-PacTrek.accdb open, use the Simple Query Wizard to create a query that displays suppliers outside British Columbia by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button.
b. At the New Query dialog box, make sure Simple Query
Wizard
is selected and then click OK.
c. At the first Simple Query
Step
1c
Wizard dialog box, click the down-pointing arrow at the right side of the Tables/
Queries
option box and then click Table: Suppliers.
d. Insert the following fields in the Selected Fields list box:
SupplierName
StreetAddress
City
Prov/State
PostalCode
e. Click the Next button.
f. At the last Simple Query
Wizard dialog box, select
Step
1e
Step
1d
the current text in the
What title do you want for your query?
text box and then type
SuppliersNotBCQuery
.
g. Click the Modify the query design option and then click the Finish button.
h. At the query window, complete the following steps:
1) Click in the Criteria row field in the Prov/State column in the query design grid.
2) Type
Not BC
and then press
enter.
Step
1f
Step
1g
104
Access Level 1
■
Unit 1
i. Specify that the fields are to be sorted in descending order by postal code by completing the following steps:
1) Click in the Sort row field in the PostalCode column.
2) Click the down-pointing arrow that displays at the right side of the field and then click Descending.
Step
1i2
j. Click the run button in the results group. (This displays suppliers that are not located in British Columbia and displays the records sorted by postal code in descending order.
See Project 1g query results on page 80.) k. Save, print, and then close the query.
2. Close AL1-C3-PacTrek.accdb.
3. Open AL1-C3-Dearborn.accdb.
4. Use the Simple Query Wizard to create a query that displays clients in Muncie by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button.
b. At the New Query dialog box, make sure Simple Query Wizard is selected and then click OK.
c. At the first Simple Query Wizard dialog box, click the down-pointing arrow at the right of the Tables/Queries option box and then click Table: Clients. (You may need to scroll up the list to display this table.) d. Insert the following fields in the Selected Fields list box:
Client
StreetAddress
City
State
ZipCode
e. Click the Next button.
f. At the last Simple Query Wizard dialog box, select the current text in the What title do
you want for your query?
text box and then type
ClientsMuncieQuery
.
g. Click the Modify the query design option and then click the Finish button.
h. At the query window, complete the following steps:
1) Click in the Criteria row field in the City column in the query design grid.
2) Type
Muncie
and then press enter.
Step
4h2
i. Click the run button in the results group. (This displays clients located in Muncie.
See Project 1g query results on page 80.) j. Save, print, and then close the query.
Chapter 3
■
Performing Queries
105
5. Close AL1-C3-Dearborn.accdb.
6. Open AL1-C3-CopperState.accdb.
7. Use the Simple Query Wizard to display clients that live in Phoenix with claims over $500 by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button in the Queries group. b. At the New Query dialog box, make sure Simple Query Wizard is selected in the list box and then click OK.
c. At the first Simple Query Wizard dialog box, click the down-pointing arrow at the right of the Tables/Queries option box and then click Table: Clients. d. Insert the following fields in the Selected Fields list box:
ClientID
FirstName
LastName
StreetAddress
City
State
ZIP
e. Click the down-pointing arrow at the right of the Tables/Queries option box and then click Table: Claims.
f. With ClaimID selected in the Available Fields list box, click the One Field button.
g. Click AmountOfClaim in the Available Fields list box and then click the One Field button.
h. Click the Next button.
i. At the second Simple Query Wizard dialog box, click the Next button.
j. At the last Simple Query Wizard dialog box, select the current text in the What title do
you want for your query?
text box and then type
PhoenixClientClaimsOver$500Query
.
k. Click the Modify the query design option and then click the Finish button.
l. At the query window, complete the following steps:
1) Click in the Criteria row field in the City column in the query design grid.
2) Type
"Phoenix"
and then press enter. (Type the quotation marks to tell Access that
this is a criterion, otherwise Access will insert the query name
PhoenixClientClaimsOver$500Query
in the Criteria field.)
3) Click in the Criteria row field in the AmountOfClaim column. (You may need to scroll to the right to display this field.)
4) Type
>500
and then press enter.
Step
7l2
Step
7l4
m. Click the run button in the results group. (This displays clients located in Phoenix with claims greater than $500. See Project 1g query results on page 80.) n. Save the query, print the query in landscape orientation, and then close the query.
8. Close AL1-C3-CopperState.accdb.
106
Access Level 1
■
Unit 1
Creating Calculated Fields
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
In a query, you can calculate values from a field by inserting a calculated field in a Field row field in the query design grid. To insert a calculated field, click in the Field row field, type the desired field name followed by a colon, and then type the equation. For example, to determine pension contributions as 3% of an employee’s annual salary, type PensionContribution:[AnnualSalary]*0.03 in the Field row field. Use brackets to specify field names and use mathematical operators to perform the equation. Some basic operators include the plus (+) for addition, the hyphen (-) for subtraction, the asterisk (*) for multiplication, and the forward slash (/) for division.
Type a calculated field in the field or in the expression Builder dialog box. To display the expression Builder dialog box, display the query in Design view, click in the field where you want the calculated field expression inserted, and then click the Builder button in the Query Setup group on the QUerY TOOLS DeSIGN tab. You can type field names in the expression Builder and when you click OK, the equation is inserted in the field with the correct symbols. For example, you can type AnnualSalary*0.03 in the expression Builder and when you click OK,
Expr1: [AnnualSalary]*0.03
is inserted in the Criteria row field. If you do not type a name for the field, Access creates the alias Expr1 for the field name. If you want a specific name for the field, such as PensionContribution, first type that in the expression Builder, followed by a colon, and then type the expression.
Builder
Project 1h
Creating a Calculated Field in a Query
Part 8 of 8
1. Open AL1-C3-MRInvestments.accdb and enable the contents.
2. Create a query that displays employer pension contributions at 3% of employees’ annual salary by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Employees in the Show Table dialog box and then click the Close button.
c. At the query window, insert the EmpID field from the Employees field list box in the first
Field
row field.
d. Insert the FirstName field in the second Field row field.
e. Insert the LastName field in the third Field row field.
f. Insert the AnnualSalary field in the fourth Field row field.
g. Click in the fifth Field row field.
h. Type
PensionContribution:[AnnualSalary]*0.03
and then press enter.
i. Click the run button in the results group.
j. Save the query and name it
PensionContributionsQuery
. (See Project 1h
Step
2h
query results on page 80.) k. Print and then close the query.
3. Modify PensionContributionsQuery and use the expression Builder to write an equation finding the total amount of annual salary plus a 3% employer pension contribution by completing the following steps: a. right-click PensionContributionsQuery in the Queries group in the Navigation pane and then click Design View at the shortcut menu.
b. Click in the field containing PensionContribution:[AnnualSalary]*0.03.
Chapter 3
■
Performing Queries
107
d. In the expression Builder, select the existing expression PensionContribution:
[AnnualSalary]*0.03
.
e. Type
Salary&Pension: [AnnualSalary]*1.03
and then click OK.
4. Click the run button in the results group.
5. Save the query by completing the following steps: a. Click the FILe tab, click the Save
As
option, click the Save Object As option, and then click the Save As button. b. At the Save As dialog box, type
Salary&PensionQuery
and then click
OK. (See Project 1h query results on page 80.)
6. Print and then close the query.
7. Close AL1-C3-MRInvestments.accdb.
Step
3e
8. Open AL1-C3-PacTrek.accdb.
9. Create a query that displays orders and total order amounts by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. Double-click Products in the Show Table dialog box.
c. Double-click Orders in the Show Table dialog box and then click the Close button.
d. At the query window, insert the Product field from the Products field list box in the first
Field
row field.
e. Insert the OrderID field from the Orders field list box in the second Field row field.
f. Insert the UnitsOrdered field from the Orders field list box in the third Field row field.
g. Insert the Amount field from the Orders field list box in the fourth Field row field.
h. Click in the fifth Field row field.
i.
Step
9j
Click the Builder button in the Query Setup group on the
QUerY TOOLS DeSIGN tab.
j. Type Total:Amount*UnitsOrdered in the expression Builder and then click OK.
k. Click the run button in the results group.
l. Adjust the width of the columns to fit the longest entries.
m. Save the query and name it UnitsOrderedTotalQuery. (See Project 1h query results on page 80.)
n. Print and then close the query.
Project
2
Create Aggregate Functions, Crosstab, Find
Duplicates, and Find Unmatched Queries
6 Parts
You will create an aggregate functions query that determines the total, average, minimum, and maximum order amounts and then calculate total and average order amounts grouped by supplier. You will also use the Crosstab, Find
Duplicates, and Find Unmatched query wizards to design queries.
108
Access Level 1
■
Unit 1
Designing Queries with Aggregate Functions
■ ■ ■ ■ ■ ■ ■ ■
You can include an aggregate function—such as Sum, Avg, Min, Max, or
Count—in a query to calculate statistics from numeric field values of all the records in the table. When an aggregate function is used, Access displays one row in the query results datasheet with the formula result for the function used. For example, in a table with a numeric field containing annual salary amounts, you can use the Sum function to calculate the total of all salary amount values.
To display the aggregate function list, click the Totals button in the Show/Hide group on the QUerY TOOLS DeSIGN tab. Access adds a Total row to the design grid with a drop-down list from which you select the desired function. Access also inserts the words Group By in the Total row field. Click the down-pointing arrow and then click the desired aggregate function from the drop-down list. In Project 2a,
Step 1, you will create a query in Design view and use aggregate functions to find the total of all sales, average sales amount, maximum and minimum sales, and total number of sales. The completed query will display as shown in Figure 3.5. Access automatically determines the column heading names.
Quick Steps
Design a Query with an Aggregate
Function
1. at query window, click totals button.
2. Click down-pointing arrow in Total row field.
3. Click desired aggregate function.
Totals
Figure 3.5
Query Results for Project 2a, Step 1
Access automatically determines the column heading names.
The aggregate functions calculate the order amounts in the Amount column in the
Orders table.
Project 2a
Using Aggregate Functions in Queries
Part 1 of 6
1. With AL1-C3-PacTrek.accdb open, create a query with aggregate functions that determines total, average, maximum, and minimum order amounts, as well as the total number of orders, by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. At the Show Table dialog box, make sure
Orders
is selected in the list box, click the Add button, and then click
Step
1c
the Close button.
c. Insert the Amount field in the first, second, third, fourth, and fifth
Field
row fields. (You may need to scroll down the Orders field list box to display the Amount field.) d. Click the Totals button in the Show/Hide group on the QUerY TOOLS DeSIGN tab. (This adds a Total row to the design grid between Table and Sort with the default option of Group By.)
Step
1d
Chapter 3
■
Performing Queries
109
e. Specify a Sum function for the first Total row field by completing the following steps:
1) Click in the first Total row field.
2) Click the down-pointing arrow that displays at the right side of the field.
3) Click Sum at the drop-down list.
f. Complete steps similar to those in Step 1e to insert Avg in the second Total row field.
Step
1e3
Step
1e2
g. Complete steps similar to those in Step 1e to insert Max in the third Total row field.
h. Complete steps similar to those in Step 1e to insert Min in the fourth Total row field.
i. Complete steps similar to those in Step 1e to insert Count in the fifth Total row field.
Step
1f
Step
1g
Step
1h
Step
1i
j. Click the run button in the results group. (Notice the headings that Access assigns to the columns.) k. Automatically adjust the widths of the columns.
l. Save the query and name it AmountsQuery. (See Project 2a query results on page 81.)
m. Print and then close the query.
2. Close AL1-C3-PacTrek.accdb.
3. Open AL1-C3-CopperState.accdb.
4. Create a query with aggregate functions that determines total, average, maximum, and minimum claim amounts by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. At the Show Table dialog box, double-click Claims.
c. Click the Close button to close the Show Table dialog box.
d. Insert the AmountOfClaim field in the first, second, third, and fourth Field row fields.
e. Click the Totals button in the Show/Hide group. f. Click in the first Total row field, click the down-pointing arrow that displays at the right side of the field, and then click Sum at the drop-down list.
Step
4f
110
Access Level 1
■
Unit 1
g. Click in the second Total row field, click the down-pointing arrow, and then click Avg at the drop-down list.
h. Click in the third Total row field, click the down-pointing arrow, and then click Max at the drop-down list.
i. Click in the fourth Total row field, click the down-pointing arrow, and then click Min at the drop-down list.
j. Click the run button in the results group. (Notice the headings that Access chooses for the columns.) k. Automatically adjust the widths of the columns.
l. Save the query and name it ClaimAmountsQuery. (See Project 2a query results on page 81.)
m. Print the query in landscape orientation and then close the query.
Using the Group By option in the Total field, you can add a field to the query on which you want Access to group records for statistical calculations.
For example, to calculate the total of all orders for a specific supplier, add the
SupplierID
field to the design grid with the Total field set to Group By. In Project
2b, Step 1, you will create a query in Design view and use aggregate functions to find the total of all order amounts and the average order amounts grouped by supplier number.
Project 2b
Using Aggregate Functions and Grouping Records
Part 2 of 6
1. With AL1-C3-CopperState.accdb open, determine the sum and average of client claims by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. At the Show Table dialog box, double-click Clients in the list box.
c. Double-click Claims in the list box and then click the Close button.
d. Insert the ClientID field from the Clients field list box to the first Field row field.
e. Insert the AmountOfClaim field from the Claims field list box to the second Field row field.
f. Insert the AmountOfClaim field from the Claims field list box to the third Field row field.
g. Click the Totals button in the Show/Hide group.
h. Click in the second Total row field, click the down-pointing arrow, and then click
Sum
at the drop-down list.
i. Click in the third Total row field, click the down-pointing arrow, and then click Avg at the drop-down list.
j. Make sure Group By displays in the first
Total
row field.
k. Click the run button in the results group.
l. Automatically adjust column widths.
Step
1j
Step
1h
Step
1i
m. Save the query and name it SumAvgClaimAmountsQuery. (See Project 2b query results on page 81.)
n. Print and then close the query.
2. Close AL1-C3-CopperState.accdb.
Chapter 3
■
Performing Queries
111
3. Open AL1-C3-PacTrek.accdb.
4. Determine the total and average order amounts for each supplier by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. At the Show Table dialog box, make sure Orders is selected in the list box and then click the Add button.
c. Click Suppliers in the list box, click the Add button, and then click the Close button.
d. Insert the Amount field from the Orders field list box to the first Field row field. (You may need to scroll down the Orders field list box to display the Amount field.) e. Insert the Amount field from the Orders field list box to the second Field row field.
f. Insert the SupplierID field from the Suppliers field list box to the third Field row field.
g. Insert the SupplierName field from the Suppliers field list box to the fourth Field row field.
h. Click the Totals button in the Show/Hide group.
i. Click in the first Total row field, click the down-pointing arrow, and then click Sum at the drop-down list.
j. Click in the second Total row field, click the down-pointing
Step
4i
arrow, and then click Avg at the drop-down list.
k. Make sure Group By displays in the third and fourth Total row fields.
Step
4j
Step
4k
l. Click the run button in the results group.
m. Automatically adjust column widths.
n. Save the query and name it SupplierAmountsQuery. (See Project 2b query results on page 81.) o. Print and then close the query.
Quick Steps
Create a Crosstab
Query
1. Click Create tab.
2. Click Query Wizard button.
3. Double-click Crosstab
Query Wizard.
4. Complete wizard steps.
Creating Crosstab Queries
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
A crosstab query calculates aggregate functions, such as Sum and Avg, in which field values are grouped by two fields. A wizard is included that guides you through the steps to create the query. The first field selected causes one row to display in the query results datasheet for each group. The second field selected displays one column in the query results datasheet for each group. A third field is specified that is the numeric field to be summarized. The intersection of each row and column holds a value that is the result of the specified aggregate function for the designated row and column group.
Create a crosstab query from fields in one table. If you want to include fields from more than one table, you must first create a query containing the desired fields, and then create the crosstab query. For example, in Project 2c, Step 2, you will create a new query that contains fields from each of the three tables in AL1-C3-
PacTrek.accdb. Using this query, you will use the Crosstab Query Wizard to create a query that summarizes the order amounts by supplier name and product ordered.
Figure 3.6 displays the results of that crosstab query. The first column displays the supplier names, the second column displays the total amount for each supplier, and the remaining columns display the amounts by suppliers for specific items.
112
Access Level 1
■
Unit 1
Figure 3.6
Crosstab Query Results for Project 2c, Step 2
Order amounts are grouped by supplier name and individual product.
Project 2c
Creating Crosstab Queries
Part 3 of 6
1. With AL1-C3-PacTrek.accdb open, create a query containing fields from the three tables by completing the following steps: a. Click the CreATe tab and then click the Query Design button.
b. At the Show Table dialog box with Orders selected in the list box, click the Add button.
c. Double-click Products in the list box.
d. Double-click Suppliers in the list box and then click the Close button.
e. Insert the following fields to the specified Field row fields:
1) From the Orders field list box, insert the ProductID field in the first Field row field.
2) From the Products field list box, insert the Product field in the second Field row field.
3) From the Orders field list box, insert the UnitsOrdered field in the third Field row field.
4) From the Orders field list box, insert the Amount field in the fourth Field row field.
5) From the Suppliers field list box, insert the SupplierName field in the fifth Field row field.
6) From the Orders field list box, insert the OrderDate field in the sixth Field row field.
Step
1e
f. Click the run button to run the query.
g. Save the query and name it ItemsOrderedQuery.
h. Close the query.
Chapter 3
■
Performing Queries
113
2. Create a crosstab query that summarizes the orders by supplier name and by product ordered by completing the following steps: a. Click the CreATe tab and then click the Query
Wizard button.
b. At the New Query dialog box, double-click Crosstab
Query Wizard
in the list box.
c. At the first Crosstab
Query Wizard dialog box, click the Queries option in the View section and then click Query: ItemsOrderedQuery in the list box.
d. Click the Next button.
e. At the second Crosstab Query
Wizard dialog box, click
SupplierName
in the Available
Fields
list box and then click the One Field button.
(This inserts SupplierName in the Selected Fields list box and specifies that you want
SupplierName
for the row headings.) f. Click the Next button.
g. At the third Crosstab Query
Wizard dialog box, click
Product
in the list box. (This specifies that you want Product for the column headings.) h. Click the Next button.
i. At the fourth Crosstab Query
Wizard dialog box, click Amount in the Fields list box and then click
Sum
in the Functions list box.
j. Click the Next button.
Step
2i
Step
2g
Step
2c
Step
2e
Step
2b
k. At the fifth Crosstab Query Wizard dialog box, select the current text in the What do you want to name
your query?
text box and then type
Step
2k
OrdersBySupplierByProductQuery
.
l. Click the Finish button. (See Project
2c query results on page 81.)
3. Display the query in Print Preview, change the orientation to landscape, change the left and right margins to 0.5 inch, and then print the query. (The query will print on four pages.)
114
Access Level 1
■
Unit 1
4. Close the query.
5. Close AL1-C3-PacTrek.accdb.
6. Open AL1-C3-CopperState.accdb.
7. Create a crosstab query from fields in one table that summarizes clients’ claims by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button.
b. At the New Query dialog box, double-click Crosstab Query Wizard in the list box.
c. At the first Crosstab Query Wizard dialog box, click Table: Claims in the list box.
d. Click the Next button.
e. At the second Crosstab Query Wizard dialog box, click the One Field button. (This inserts the ClaimID field in the Selected Fields list box.) f. Click the Next button.
g. At the third Crosstab Query Wizard dialog, make sure ClientID is selected in the list box and then click the Next button.
h. At the fourth Crosstab Query Wizard dialog box, click AmountOfClaim in the Fields list box and click Sum in the Functions list box.
i. Click the Next button.
j. At the fifth Crosstab Query Wizard dialog box, select the current text in the What do you
want to name your query?
text box and then type
ClaimsByClaimIDByClientIDQuery
.
k. Click the Finish button. (See Project 2c query results on page 81.)
8. Change the orientation to landscape and then print the query. The query will print on two pages.
9. Close the query.
10. Close AL1-C3-CopperState.accdb.
Creating Find Duplicates Queries
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
Use a find duplicates query to search a specified table or query for duplicate field values within a designated field or fields. Create this type of query, for example, if you suspect a record (such as a product record) has inadvertently been entered twice (perhaps under two different product numbers). A find duplicates query has many applications. Here are a few other examples of how you can use a find duplicates query:
• In an orders table, find records with the same customer number so you can identify loyal customers.
• In a customers table, find records with the same last name and mailing address so you can send only one mailing to a household and save on printing and postage costs.
• In an employee expenses table, find records with the same employee number so you can see which employee is submitting the most claims.
Access provides the Find Duplicates Query Wizard to build the query based on the selections made in a series of dialog boxes. To use this wizard, open the desired database, click the CreATe tab, and then click the Query Wizard button.
At the New Query dialog box, double-click Find Duplicates Query Wizard in the list box and then complete the steps provided by the wizard.
In Project 2d, you will assume that you have been asked to update the address for a supplier in AL1-C3-PacTrek.accdb. Instead of updating the address, you create a new record. You will then use the Find Duplicates Query Wizard to find duplicate field values in the Suppliers table.
Quick Steps
Create a Find
Duplicates Query
1. Click Create tab.
2. Click Query Wizard button.
3. Double-click Find
Duplicates Query
Wizard.
4. Complete wizard steps.
Chapter 3
■
Performing Queries
115
Project 2d
Creating a Find Duplicates Query
Part 4 of 6
1. Open AL1-C3-PacTrek.accdb and then open the Suppliers table.
2. Add the following record to the table:
SupplierID#
29
SupplierName
Langley Corporation
StreetAddress
1248 Larson Avenue
City
Burnaby
BC
Prov/State
PostalCode
V5V 9K2
EmailAddress
Telephone
(604) 555-1200
3. Close the Suppliers table.
4. Use the Find Duplicates Query Wizard to find any duplicate supplier names by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button.
b. At the New Query dialog box, double-click Find Duplicates Query Wizard.
c. At the first wizard dialog box, click Table: Suppliers in the list box.
d. Click the Next button.
e. At the second wizard dialog box, click SupplierName in the
Available fields
list box and then click the One Field button.
(This moves the SupplierName field to the Duplicate-value fields list box.) f. Click the Next button.
g. At the third wizard dialog box, click the All Fields button (the button containing the two greaterthan symbols, >>). This moves all the fields to
Step
4c
the Additional query fields list box. You are doing this because if you find a duplicate supplier name, you want to view all the fields to determine which record is accurate.
h. Click the Next button.
i. At the fourth (and last) wizard dialog box, type
DuplicateSuppliersQuery
in the What do you want
to name your query?
text box.
j. Click the Finish button. (See
Project 2d query results on page 81.) k. Change the orientation to landscape and then print the query.
5. As you look at the query results, you realize that an inaccurate record was entered for the Langley
Corporation, so you decide to delete one of the records. To do this, complete the following steps:
Step
4i
Step
4e
116
Access Level 1
■
Unit 1
a. With the query open, click in the record selector bar next to the record with a supplier
ID of 29. (This selects the entire row.) b. Click the HOMe tab and then click the Delete button in the records group.
Step
5b
c. At the message asking you to confirm, click the
Yes button.
Step
5a
d. Close the query.
6. Change the street address for Langley Corporation by completing the following steps: a. Open the Suppliers table in Datasheet view.
b. Change the address for Langley Corporation from 805 First Avenue to 1248 Larson Avenue.
Leave the other fields as displayed.
c. Close the Suppliers table.
In Project 2d, you used the Find Duplicates Query Wizard to find records containing the same field.In Project 2e, you will use the Find Duplicates Query
Wizard to find information on the suppliers you order from the most. You could use this information to negotiate for better prices or to ask for discounts.
Project 2e
Finding Duplicate Orders
Part 5 of 6
1. With AL1-C3-PacTrek.accdb open, create a query with the following fields (in the order shown) from the specified tables:
SupplierID
Suppliers table
SupplierName
Suppliers table
ProductID
Product
Orders table
Products table
2. run the query.
3. Save the query with the name SupplierOrdersQuery and then close the query.
4. Use the Find Duplicates Query Wizard to find the suppliers you order from the most by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button.
b. At the New Query dialog box, doubleclick Find Duplicates Query Wizard.
c. At the first wizard dialog box, click the
Queries
option in the View section and then click Query: SupplierOrdersQuery.
(You may need to scroll down the list to display this query.)
Step
4c
Chapter 3
■
Performing Queries
117
d. Click the Next button.
e. At the second wizard dialog box, click SupplierName in the Available fields list box and then click the One Field button.
f. Click the Next button.
g. At the third wizard dialog box, click the Next button.
h. At the fourth (and last) wizard dialog box, type
SupplierOrdersCountQuery
in the What do you want to name your
query?
text box.
i. Click the Finish button.
j. Adjust the widths of the columns to fit the longest entries.
k. Print the query. (See Project 2e query results on page 82.)
5. Close the query.
Step
4h
Quick Steps
Create a Find
Unmatched Query
1. Click Create tab.
2. Click Query Wizard button.
3. Double-click Find
Unmatched Query
Wizard.
4. Complete wizard steps.
Creating Find Unmatched Queries
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
Create a find unmatched query to compare two tables and produce a list of the records in one table that have no matching record in the other table. This type of query is useful to produce lists such as customers who have never placed orders and invoices that have no records of payment. Access provides the Find Unmatched
Query Wizard to build the select query by guiding you through a series of dialog boxes.
In Project 2f, you will use the Find Unmatched Query Wizard to find all of the products that have no units on order. This information is helpful in identifying which products are not selling and might need to be discontinued or returned. To use the Find Unmatched Query Wizard, click the CreATe tab and then click the Query Wizard button in the Queries group. At the New Query dialog box, double-click Find Unmatched Query Wizard in the list box and then follow the wizard steps.
Project 2f
Creating a Find Unmatched Query
Part 6 of 6
1. With AL1-C3-PacTrek.accdb open, use the Find Unmatched Query Wizard to find all products that do not have units on order by completing the following steps: a. Click the CreATe tab and then click the Query Wizard button.
b. At the New Query dialog box, double-click Find
Unmatched Query Wizard
.
c. At the first wizard dialog box, click Table: Products in the list box. (This is the table containing the fields you want to see in the query results.) d. Click the Next button.
e. At the second wizard dialog box, make sure Table:
Orders
is selected in the list box. (This is the table containing the related records.) f. Click the Next button.
Step
1c
118
Access Level 1
■
Unit 1
g. At the third wizard dialog box, make sure ProductID is selected in both the Fields in
'Products'
list box and in the
Fields in 'Orders'
list box.
h. Click the Next button.
i. At the fourth wizard dialog box, click the All Fields button to move all of the fields from the Available fields list box to the Selected fields list box.
j. Click the Next button.
k. At the fifth wizard dialog box, click the Finish button. (Let the wizard determine the query name: Products Without Matching
Step
1g
Orders
. See Project 2f query results on page 82.)
2. Print the query in landscape orientation and then close the query.
3. Close AL1-C3-PacTrek.accdb.
Chapter Summary
■
One of the most important uses of a database is to select the information needed to answer questions and make decisions. Data can be extracted from an Access database by performing a query, which can be accomplished by designing a query or using a query wizard.
■
Designing a query consists of identifying the table, the field or fields from which the data will be drawn, and the criteria for selecting the data.
■
In designing a query, type the criterion (or criteria) for extracting the specific data. Access inserts any necessary symbols in the criterion when the enter key is pressed.
■
In a criterion, quotation marks surround field values and pound symbols (#) surround dates. Use the asterisk (*) as a wildcard character.
■
You can perform a query on fields within one table or on fields from related tables.
■
When designing a query, you can specify the sort order of a field or fields.
■
You can modify an existing query and use it for a new purpose.
■
enter a criterion in the or row in the query design grid to instruct Access to display records that match any of the criteria.
■
Multiple criteria entered in the Criteria row in the query design grid become an
And
statement, where each criterion must be met for Access to select the record.
■
The Simple Query Wizard guides you through the steps for preparing a query.
You can modify a query you create with the wizard.
■
You can insert a calculated field in a Field row field when designing a query.
Chapter 3
■
Performing Queries
119
■
Include an aggregate function (such as Sum, Avg, Min, Max, or Count) to calculate statistics from numeric field values. Click the Totals button in the Show/Hide group on the QUerY TOOLS DeSIGN tab to display the aggregate function list.
■
Use the Group By option in the Total row field to add a field to a query on which you want Access to group records for statistical calculations.
■
Create a crosstab query to calculate aggregate functions (such as Sum and Avg), in which fields are grouped by two. Create a crosstab query from fields in one table. If you want to include fields from more than one table, create a query first and then create the crosstab query.
■
Use a find duplicates query to search a specified table for duplicate field values within a designated field or fields.
■
Create a find unmatched query to compare two tables and produce a list of the
Commands Review
FEATURE
add Total row to query design
RIBBON TAB, GROUP
QUERY TOOLS DESIGN, Show/Hide
Crosstab Query Wizard
Find Duplicates Query Wizard
Find Unmatched Query Wizard
New Query dialog box query results query window
Simple Query Wizard
CREATE, Queries
CREATE, Queries
CREATE, Queries
CREATE, Queries
QUERY TOOLS DESIGN, Results
CREATE, Queries
CREATE, Queries
BUTTON, OPTION
, Crosstab Query Wizard
, Find Duplicates Query Wizard
, Find Unmatched Query Wizard
, Simple Query Wizard
120
Access Level 1
■
Unit 1
Concepts Check
Test Your Knowledge
records in one table that have no matching records in the other related table.
Completion: In the space provided at the right, indicate the correct term, symbol, or command.
1. The Query Design button is located in the Queries group on this tab.
2. Click the Query Design button and the query window displays with this dialog box open.
_____________________
_____________________
3. To establish a criterion for a query, click in this row in the column containing the desired field name and then type the criterion. _____________________
4. This is the term used for the results of the query. _____________________
5. This is the symbol Access automatically inserts before and after a date when writing a criterion for the query. _____________________
6. Use this symbol to indicate a wildcard character when writing a query criterion.
7. This is the criterion you would type to return field values greater than $500.
8. This is the criterion you would type to return field values that begin with the letter L.
_____________________
_____________________
_____________________
9. This is the criterion you would type to return field values that are not in Oregon. _____________________
10. You can sort a field in a query in ascending order or in this order. _____________________
11. Multiple criteria entered in the Criteria row in the query design grid become this type of statement. _____________________
12. This wizard guides you through the steps for preparing a query. _____________________
13. This type of query calculates aggregate functions, in which field values are grouped by two fields.
14. Use this type of query to compare two tables and produce a list of the records in one table that have no matching records in the other table.
_____________________
_____________________
Chapter 3
■
Performing Queries
121
Skills Check
Assess Your Performance
Assessment
1
Design Queries in a legal serViCes DataBase
Grade It
1. Display the Open dialog box with the AL1C3 folder on your storage medium the active folder.
2. Open AL1-C3-WarrenLegal.accdb and enable the contents.
3. Design a query that extracts information from the Billing table with the following specifications: a. Include the fields BillingID, ClientID, and CategoryID in the query.
b. extract those records with the SE category. (Type "SE" in the Criteria row field in the CategoryID column. You need to type the quotation marks to tell
Access that Se is a criterion and not a built-in Access function.) c. Save the query and name it SECategoryBillingQuery.
d. Print and then close the query.
4. Design a query that extracts information from the Billing table with the following specifications: a. Include the fields BillingID, ClientID, and Date.
b. extract those records in the Date field with dates between 6/8/2015 and 6/15/2015.
c. Save the query and name it June8-15BillingQuery.
d. Print and then close the query.
5. Design a query that extracts information from the Clients table with the following specifications: a. Include the fields FirstName, LastName, and City.
b. extract those records with cities other than Kent in the City field.
c. Save the query and name it ClientsNotInKentQuery.
d. Print and then close the query.
6. Design a query that extracts information from two tables with the following specifications: a. Include the fields BillingID, ClientID, Date, and RateID from the Billing table.
b. Include the field Rate from the rates table.
c. extract those records with rate IDs greater than 2.
d. Save the query and name it RateIDGreaterThan2Query.
e. Print and then close the query.
7. Design a query that extracts information from three tables with the following specifications: a. Include the fields AttorneyID, FName, and LName from the Attorneys table.
b. Include the fields FirstName and LastName from the Clients table.
c. Include the fields Date and Hours from the Billing table.
d. extract those records with an attorney ID of 12.
e. Save the query and name it Attorney12Query.
f. Print and then close the query.
8. Design a query that extracts information from four tables with the following specifications: a. Include the fields AttorneyID, FName, and LName from the Attorneys table.
b. Include the field Category from the Categories table.
c. Include the fields RateID and Rate from the rates table.
122
Access Level 1
■
Unit 1
d. Include the fields Date and Hours from the Billing table.
e. extract those records with an attorney ID of 17 and a rate ID of 4.
f. Save the query and name it Attorney17RateID4Query.
g. Print the query in landscape orientation and then close the query.
9. Open the Attorney17rateID4Query query, click the View button on the
HOMe tab to display the query in Design view, and then modify the query so it displays records with a rate ID of 4 and attorney IDs of 17 and 19 by making the following changes: a. Click below the field value "17 " in the AttorneyID column and then type
19
.
b. Click below the field value "4" in the RateID column, type
4
, and then press enter.
c. run the query.
d. Save the query with the new name Attorney17&19RateID4Query. Hint: Do
this at the Save As dialog box. Display this dialog box by clicking the FILE
tab, clicking the Save As option, clicking the Save Object As option, and
then clicking the Save As button.
e. Print the query in landscape orientation and then close the query.
Assessment
2
use tHe siMple Query WiZarD anD Design Queries
Grade It
1. With AL1-C3-WarrenLegal.accdb open, use the Simple
Query Wizard to extract specific information from three tables with the following specifications: a. At the first Simple Query Wizard dialog box, include the following fields:
From Attorneys table: AttorneyID, FName, and LName
From Categories table: Category
From Billing table: Hours b. At the second Simple Query Wizard dialog box, click Next.
c. At the third Simple Query Wizard dialog box, click the Modify the query
design
option and then click the Finish button.
d. At the query window, insert 14 in the Criteria row field in the AttorneyID column.
e. run the query.
f. Save the query with the default name.
g. Print and then close the query.
2. Create a query in Design view with the Billing table with the following specifications: a. Insert the Hours field from the Billing field list box to the first, second, third, and fourth Field row fields.
b. Click the Totals button in the Show/Hide group.
c. Insert Sum in the first Total row field.
d. Insert Min in the second Total row field.
e. Insert Max in the third Total row field.
f. Insert Count in the fourth Total row field.
g. run the query.
h. Automatically adjust the widths of the columns.
i. Save the query and name it HoursAmountQuery.
j. Print and then close the query.
3. Create a query in Design view with the following specifications: a. Add the Attorneys table and Billing table to the query window.
b. Insert the FName field from the Attorneys field list box to the first Field row field.
c. Insert the LName field from the Attorneys field list box to the second Field row field.
Chapter 3
■
Performing Queries
123
d. Insert the AttorneyID field from the Billing field list box to the third Field row field. (You will need to scroll down the Billing field list box to display the AttorneyID field.)
e. Insert the Hours field from the Billing field list box to the fourth Field row field.
f. Click the Totals button in the Show/Hide group.
g. Insert Sum in the fourth Total row field in the Hours column.
h. run the query.
i. Save the query and name it AttorneyHoursQuery.
j. Print and then close the query.
4. Create a query in Design view with the following specifications: a. Add the Attorneys, Clients, Categories, and Billing tables to the query window.
b. Insert the AttorneyID field from the Attorneys field list box to the first Field row field.
c. Insert the ClientID field from the Clients field list box to the second Field row field.
d. Insert the Category field from the Categories field list box to the third Field row field.
e. Insert the Hours field from the Billing field list box to the fourth Field row field.
f. run the query.
g. Save the query and name it AttorneyClientHours.
h. Print and then close the query.
Assessment
3
Create a CrosstaB Query anD use tHe FinD DupliCates anD FinD unMatCHeD Query WiZarDs
Grade It
1. With AL1-C3-WarrenLegal.accdb open, create a crosstab query that summarizes the hours by attorney by category with the following specifications: a. At the first Crosstab Query Wizard dialog box, click the Queries option in the View section and then click Query: AttorneyClientHours in the list box.
b. At the second Crosstab Query Wizard dialog box with AttorneyID selected in the Available Fields list box, click the One Field button.
c. At the third Crosstab Query Wizard dialog box, click Category in the list box.
d. At the fourth Crosstab Query Wizard dialog box, click Hours in the Fields list box and click Sum in the Functions list box.
e. At the fifth Crosstab Query Wizard dialog box, select the current name in the What do you want to name your query? text box and then type
HoursByAttorneyByCategory
.
f. Display the query in Print Preview, change to landscape orientation, change the left and right margins to 0.5 inch, and then print the query.
g. Close the query.
2. Use the Find Duplicates Query Wizard to find those clients with the same last name with the following specifications: a. At the first wizard dialog box, click Table: Clients in the list box.
b. At the second wizard dialog box, click LastName in the Available fields list box and then click the One Field button.
c. At the third wizard dialog box, click the All Fields button.
124
Access Level 1
■
Unit 1
d. At the fourth wizard dialog box, name the query DuplicateLastNamesQuery.
e. Print the query in landscape orientation and then close the query.
3. Use the Find Unmatched Query Wizard to find all clients who do not have any billing hours with the following specifications: a. At the first wizard dialog box, click Table: Clients in the list box.
b. At the second wizard dialog box, click Table: Billing in the list box.
c. At the third wizard dialog box, make sure ClientID is selected in both the
Fields in 'Clients'
list box and in the Fields in 'Billing' list box.
d. At the fourth wizard dialog box, click the All Fields button to move all fields from the Available fields list box to the Selected fields list box.
e. At the fifth wizard dialog box, click the Finish button. (Let the wizard determine the query name: Clients Without Matching Billing.)
4. Print the query in landscape orientation and then close the query.
Assessment
4
Design anD HiDe FielDs in a Query
1. You can use the check boxes in the query design grid Show row to show or hide fields in the query. experiment with these check boxes and then with
AL1-C3-WarrenLegal.accdb open design the following query:
a. At the Show Table dialog box, add the Clients table, the Billing table, and the rates table.
b. At the query window, insert the following fields in Field row fields:
Clients table: FirstName
LastName
Billing table: Hours
rates table: Rate c. Insert in the fifth Field row field the calculated field Total:[Hours]*[Rate].
d. Hide the Hours and Rate fields.
e. run the query.
f. Save the query and name it ClientBillingQuery.
g. Print and then close the query. (The query will print on two pages.)
2. Close AL1-C3-WarrenLegal.accdb.
Visual Benchmark
Demonstrate Your Proficiency
Creating relationsHips anD Designing a Query
1. Open AL1-C3-MRInvestments.accdb from the AL1C3 folder on your storage medium and, if necessary, enable the contents.
2. Display the relationships window and then create the relationships shown in Figure 3.7. enforce referential integrity and cascade fields and records.
(The tables in Figure 3.7 have been rearranged in the relationships window so you have a better view of the relationships.)
3. Save and then print the relationships.
4. Close the relationship report without saving it and then close the relationships window.
5. Design the query shown in Figure 3.8.
Chapter 3
■
Performing Queries
125
6. run the query.
7. Save the query with an appropriate name and then print the query.
8. Close AL1-C3-MRInvestments.accdb.
Figure 3.7
Visual Benchmark Relationships Window
Figure 3.8
Visual Benchmark Query
126
Access Level 1
■
Unit 1
Case Study
Apply Your Skills
Part
1
You work for the Skyline restaurant in Fort Myers, Florida. Your supervisor is reviewing the restaurant’s operations and has asked for a number of query reports. Before running the queries, you realize that the tables in the restaurant database, AL1-C3-Skyline.accdb, are not related. Open AL1-C3-Skyline.
accdb, enable the contents, and then create the following relationships (enforce
referential integrity and cascade fields and records):
Field Name “One” Table “Many” Table
EmployeeID
employees Banquets
ItemID
Inventory Orders
SupplierID
Suppliers Orders
SupplierID
Suppliers Inventory
EventID
events Banquets
Save and then print the relationships. Close the relationship report without saving it and then close the relationships window.
Part
2
As part of the review of the restaurant’s records, your supervisor has asked you for the following information. Create a separate query for each bulleted item listed below and save, name, and print the queries. (You determine the query names.)
• Suppliers in Fort Myers: From the Suppliers table, include the supplier identification number, supplier name, city, and telephone number.
• Suppliers not located in Fort Myers: From the Suppliers table, include the supplier identification number and supplier name, city, and telephone number.
• employees hired in 2012: From the employees table, include the employee identification number, first and last names, and hire date.
• employees signed up for health insurance: From the employees table, include employee first and last names and the health insurance field.
• Wedding receptions (event identification "Wr") booked in the banquet room: From the Banquets table, include the reservation identification number; reservation date; event identification; and first name, last name, and telephone number of the person making the reservation.
• Banquet reservations between 6/14/2015 and 6/30/2015 and the employees making the reservations: From the Banquets table, include the reservation identification number; reservation date; and first name, last name, and telephone number of the person making the reservation; from the employees table include the employee first and last names.
• Banquet reservations that have not been confirmed and the employees making the reservations: From the Banquets table, include the reservation identification number; reservation date; confirmed field; and first and last names of person making the reservation; from the employees table, include employee first and last names.
• Banquet room reserved by someone whose last name begins with the letters
Wie:
From the employees table, include the first and last names of the employee who booked the reservation; from the Banquets table, include the first and last names and telephone number of the person making the reservation.
Chapter 3
■
Performing Queries
127
• A query that inserts a calculated field that multiplies the number of units ordered by the unit price for all orders for supplier number 2: From the Orders table, include the order identification number, the supplier identification number, the units ordered, and the unit price; from the
Inventory table, include the item field.
Part
3
Use the Find Duplicates Query Wizard to find duplicate items in the Orders table with the following specifications:
• At the first wizard dialog box, specify the Orders table.
• At the second wizard dialog box, specify ItemID as the duplicate value field.
• At the third wizard dialog, specify that you want all of the fields in the query.
• At the fourth wizard dialog box, determine the query name.
• Print and then close the query.
Use the Find Unmatched Query Wizard to find all of the employees who have not made banquet reservations with the following specifications:
• At the first wizard dialog box, specify the employees table.
• At the second wizard dialog box, specify the Banquets table.
• At the third wizard dialog box, specify the EmployeeID field in both list boxes.
• At the fourth wizard dialog box, specify that you want all of the fields in the query.
• At the fifth wizard dialog box, determine the query name.
• Print the query in landscape orientation with 0.5-inch left and right margins and then close the query.
Use the Crosstab Query Wizard to create a query that summarizes order amounts by supplier with the following specifications:
• At the first wizard dialog box, specify the Orders table.
• At the second wizard dialog box, specify the SupplierID field for row headings.
• At the third wizard dialog box, specify the ItemID field for column headings.
• At the fourth wizard dialog box, click UnitPrice in the Fields list box and click Sum in the Functions list box.
• At the fifth wizard dialog box, determine the query name.
• Automatically adjust the columns in the query. (You will need to scroll to the right to view and adjust all of the columns containing data.)
• Print the query in landscape orientation and then close the query.
Part
4
Design three additional queries that require fields from at least two tables. run the queries and then save and print the queries. In Microsoft Word, write the query information (including specific information about each query) and format the document to enhance the visual appearance. Save the document and name it
AL1-C3-CS-Queries. Print and then close AL1-C3-CS-Queries.docx. Close
AL1-C3-Skyline.accdb.
128
Access Level 1
■
Unit 1
Download
Anúncio