access queries
DESCRIPTION
Access Queries. Office 2013/365. Queries. Most common type of Query is selection(projection) Specify sources for data retrieval table(s) and/or query( ies ) Specify attributes(fields) to be retrieved Selection criteria Calculations that need to be performed Action Queries - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/1.jpg)
Access Queries
Office 2013/365
1
![Page 2: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/2.jpg)
Queries
• Most common type of Query is selection(projection)• Specify sources for data retrieval
• table(s) and/or query(ies)
• Specify attributes(fields) to be retrieved• Selection criteria• Calculations that need to be performed
• Action Queries• Other types such as crosstabs
2
![Page 3: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/3.jpg)
3
Query Creation
• Structured Query Language (SQL)• The user enters commands according to a pre-
defined syntax to retrieve desired data. • Query By Example (QBE)
• The user starts with a sample of the table(s) columns and marks the fields he or she wants to include in the answer.
• Defaults are available for summarizing and manipulating the data.
![Page 4: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/4.jpg)
Creating Queries
• Query Wizard • QBE Query Design
• The user starts with a sample of the table(s) columns and marks the fields he or she wants to include in the answer.
• Defaults are available for summarizing and manipulating the data.
• SQL design (beyond scope of our class)• The user enters commands according to a pre-defined
syntax to retrieve desired data.
4
![Page 5: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/5.jpg)
Creating Query• Wizards
• Click on create tab • Select query wizard • Select simple query• Select your data source(s)• Select desired attributes from each data source• Select next• Name query• Click on finish
• Limitation• May be able to do a summary calculation, but not a
calculated field
5
![Page 6: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/6.jpg)
6
Wizard
Click on create tab and select Query Wizard
![Page 7: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/7.jpg)
7
Click on Simple Query wizard
![Page 8: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/8.jpg)
8
Select data sources and desired attributes from each source
![Page 9: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/9.jpg)
9
Name your query
![Page 10: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/10.jpg)
10
Resulting Dynaset
![Page 11: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/11.jpg)
• Access creates the SQL needed to do the query for the wizard
• SQL for previous query example
11
SELECT Customers.[ID], Customers.[Last Name], Customers.[First Name], Customers.[E-mail Address], Customers.[Job Title], Customers.[Business Phone]FROM Customers;
![Page 12: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/12.jpg)
Design View• Uses QBE (what we will use)• Design View
• Click on create tab • Select query design• Select your data sources and click on add• Select attributes from each data source and drag
to grid below• Run query• Save query if it will be used on a regular basis
• Can create calculated fields
12
![Page 13: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/13.jpg)
13
Click on create tab and select Query Design
![Page 14: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/14.jpg)
14
Select your data sources and click on add
![Page 15: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/15.jpg)
15
Select attributes from each data source and double click or drag to grid below
![Page 16: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/16.jpg)
16
Select design tab and Click on Run symbol to execute query
![Page 17: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/17.jpg)
17
Resulting Dynaset
SQLSELECT Customers.[ID], Customers.[Last Name], Customers.[First Name], Customers.[E-mail Address], Customers.[Job Title], Customers.[Business Phone]FROM Customers;
![Page 18: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/18.jpg)
18
Examples to follow based on this
database
![Page 19: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/19.jpg)
19
Customer table data
![Page 20: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/20.jpg)
Queries with selection criteria
• Use design view when using selection criteria
• Select your data sources and attributes of interest from your data sources enter selection criteria
• Run query
20
![Page 21: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/21.jpg)
21
Selection Criteria
Query to list Customers from CA
![Page 22: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/22.jpg)
22
Resulting Dynaset
SQLSELECT Customers.ID, Customers.Company, Customers.City, Customers.[State/Province]FROM CustomersWHERE (((Customers.[State/Province])="CA"));
![Page 23: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/23.jpg)
23
Queries(complex selection criteria)
• Comparison operators • <, • >,• =, • <=,• >=, and • <> Not equal to
• Logical operators• And,• Or, and • Not
![Page 24: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/24.jpg)
24
Multiple Criteria
• AND operator• Queries that must satisfy more than one condition,
with all conditions being true, use the AND operator
• OR operator• When any one of several criteria is all that is
required for a row to be displayed in a dynaset, then you use the OR operator
![Page 25: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/25.jpg)
And Operator
25
Selection Criteria
![Page 26: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/26.jpg)
Resulting Dynaset
26
SQLSELECT Customers.ID, Customers.Company, Customers.CityFROM CustomersWHERE (((Customers.City)="Los Angelas") AND ((Customers.[State/Province])="CA"));
![Page 27: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/27.jpg)
OR Operator
27Selection Criteria
![Page 28: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/28.jpg)
28
Resulting Dynaset
SQLSELECT Customers.ID, Customers.Company, Customers.CityFROM CustomersWHERE (((Customers.[State/Province])="CA")) OR (((Customers.[State/Province])="UT"));
![Page 29: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/29.jpg)
29
Action queries • Action Queries
• Make table • Append • update • Delete
• Action queries alter information as opposed to selection queries, which passively display information without altering anything
• Back up data before performing action queries• No undo
![Page 30: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/30.jpg)
Action Queries• Make Table
• Query selects records from data base and saves the records in a new table
• Append• Make query add records to an existing table
• Update• Make query update data in an existing table
• Delete• Make the query delete the information from an
existing table where the data matches the criteria
30
![Page 31: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/31.jpg)
Action Queries
• Use design view to perform action queries• Select create tab • Query design• Select data source(s)• Select data and/or selection criteria• Select design, select action query• Save query• Run query• You will get a pop-up message indicating what
the query is about to do
31
![Page 32: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/32.jpg)
32
Depending on action query selected you need to specify fields and/or criteria
Make table, Append, Update, Delete
![Page 33: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/33.jpg)
Example Action query message
33
![Page 34: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/34.jpg)
Example Action query message
34
![Page 35: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/35.jpg)
Append Query Considerations
• Select the table containing the data you want to add• Source may be internal or external
• Select the destination• Fields must be of like data type• Field mapping
35
![Page 36: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/36.jpg)
36
Source Destination
![Page 37: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/37.jpg)
37
Note: 1. Access has attempting to map the fields from tblCA to
table customer2. Access maps all fields between the two tables with the
same field names
![Page 38: Access Queries](https://reader035.vdocuments.site/reader035/viewer/2022062422/56813d27550346895da6ec2e/html5/thumbnails/38.jpg)
38
Note: 1. Since the two tables used a different names for this field,manual mapping required