Succeeding in Business with Microsoft Access 2013
Analyzing Data For Effective Decision Making
Succeeding in Business with Microsoft Access 2013
Chapter Introduction
• Filter data in a Microsoft Office Access 2013 database– Retrieve and examine only the records you need– Sort data to rearrange records in a specified order
• Create complex queries• Explore advanced queries• Explore queries written in Structured Query
Language
2
Succeeding in Business with Microsoft Access 2013
Tools Covered In This Chapter
• Action queries (update, append, delete, crosstab, and make-table)
• Aggregate functions (Avg, Max, Min, Sum)• Calculated field• Comparison and logical operators• Crosstab query• Filter by Form and Filter by Selection• Find duplicates query• Find unmatched records query
3
Succeeding in Business with Microsoft Access 2013
Tools Covered In This Chapter (cont’d.)
• Immediate IF (IIF) function• Parameter query• Design View• Select query• Simple Query Wizard• SQL commands• Top Values query• Wildcard character
4
Succeeding in Business with Microsoft Access 2013
Level 1 Objectives: Organizing and Retrieving Information from a Database
• Filter and sort data to make it more meaningful
• Create simple queries to answer business questions
• Develop queries using comparison criteria and wildcards
• Verify and print query results
5
Succeeding in Business with Microsoft Access 2013 6
Filtering and Sorting Data
• Filter – Restricts data in single table to create temporary
subset of records– See only certain records in table based on
specified criteria• Sorting records – Organizing in particular order or sequence– Sort records regardless of whether table filtered
Succeeding in Business with Microsoft Access 2013 7
Filtering by Selection
• Tools– Filter by Selection• Select particular field in datasheet • Display only data that matches contents of field• Specify only one criterion for filter
– Filter by Form
Succeeding in Business with Microsoft Access 2013 8
Succeeding in Business with Microsoft Access 2013 9
Filtering by Form
• Specify two or more criteria• Filter for comparative data– Use comparison operators
• AND criteria– Selects records that contain all specified values
• OR criteria– Selects records that contain any of specified values
Succeeding in Business with Microsoft Access 2013 10
Sorting Data to Increase Information Content
• Lets you view the information in a variety of ways• Access sorts records based on primary key values– Use sorting to change order
• To sort– Select sort field
• Sort on multiple fields– Move fields in Datasheet view so that they are
adjacent
Succeeding in Business with Microsoft Access 2013 11
Sorting Data To Increase Information Content (cont’d.)
• How Access sorts different types of data
Succeeding in Business with Microsoft Access 2013 12
Filtering Using the Filter Arrow
Succeeding in Business with Microsoft Access 2013 13
Using Queries to Answer Business Questions
• Query – Database object – Stores criteria for selecting records from one or
more tables based – Save query • Use it again
– More powerful than filter• Display only some fields in table• Create fields that perform calculations
Succeeding in Business with Microsoft Access 2013 14
Using Queries to Answer Business Questions (cont’d.)
• Capabilities of Access queries:– Display selected fields and records from table– Sort records on one or multiple fields– Perform calculations– Generate data for forms, reports, and other queries– Update data in database– Find and display data from two or more tables– Create new tables– Delete records in table based on one or more criteria
Succeeding in Business with Microsoft Access 2013 15
Using Queries to Answer Business Questions (cont’d.)
• Select query– Ask question based on one or more tables in
database– Result displayed in datasheet• Called recordset
Succeeding in Business with Microsoft Access 2013 16
Using the Simple Query Wizard to Create a Query
• Simple query wizard – Presents list of tables and queries in database • And fields that they contain
– Select fields from one or more tables– Wizard creates and displays results
Succeeding in Business with Microsoft Access 2013 17
Including Summary Statistics in a Query for Data Analysis
• Summary query – Groups records – Calculate sum, average, minimum, or maximum
value in each selected field– Count records in table or query
• Click Summary Options button
Succeeding in Business with Microsoft Access 2013 18
Figure 3.7: Creating a summary query with the Simple Query Wizard
Succeeding in Business with Microsoft Access 2013 19
Creating a Query in Design View
• Select Query window in Design view has two sections – Area for field lists at top of window – Design grid below it
• Add tables for query to top part of window– Appear as field lists
• Query by example (QBE)– Typing search value as a criterion
Succeeding in Business with Microsoft Access 2013 20
Succeeding in Business with Microsoft Access 2013 21
Creating Queries with Multiple Criteria
• Most queries involve more than one criterion• Represent AND criteria– Enter conditions in same criteria row in query
design grid• Specify OR criteria– Use “or” row of query design grid
Succeeding in Business with Microsoft Access 2013 22
Figure 3.10: Setting criteria for the query in Design view
Succeeding in Business with Microsoft Access 2013
Specifying Sort Order in Queries
• Query results appear in same order as data from underlying tables – Unless specify sort order when designing query
• Sort order determined from left to right
23
Succeeding in Business with Microsoft Access 2013 24
Running a Query
• Click Run button in the Results group– Access displays datasheet of records
• Save query– Save only design– Not values from tables displayed in results
Succeeding in Business with Microsoft Access 2013 25
Enhancing Query Criteria to Improve Data Analysis
• Expand criteria by using – Wildcards – Comparison operators
Succeeding in Business with Microsoft Access 2013 26
Using Wildcards for Inexact Query Matches
• Wildcard character– Placeholder – Stands for one or more characters
• Comment fields– Use same keywords throughout comments– Easily retrieve records later– Use wildcards when specifying keyword as a query
criterion • To select records that contain characters before and after
keyword
Succeeding in Business with Microsoft Access 2013 27
Succeeding in Business with Microsoft Access 2013 28
Using Wildcards for Inexact Query Matches (cont’d.)
• Access inserts – Word “LIKE” for criteria with wildcards quotation
marks around text• LIKE “*Spanish*”
– Pound signs around dates• #12/*/2013#
Succeeding in Business with Microsoft Access 2013 29
Using Comparison Operators to Refine Query Criteria
• Comparison operators– Compare value in field with range of values in
criterion• Clear the design grid to create or modify a
query– Start with same field list but blank grid
Succeeding in Business with Microsoft Access 2013 30
Succeeding in Business with Microsoft Access 2013 31
Verifying and Printing Query Results
• Verify query results before– Distributing query to others – Using it as basis for decisions
• Use business knowledge – Determine whether results adequately answer
question• Print query datasheet
Succeeding in Business with Microsoft Access 2013
Modifying Query Datasheets
• Improve appearance of query or table datasheet
• Resize column widths in any datasheet – Double-click line between field names to resize
columns to best fit
32
Succeeding in Business with Microsoft Access 2013 33
Succeeding in Business with Microsoft Access 2013
Level 1 Summary
• Use filtering and sorting to change data display
• Develop queries using– Simple query wizard– Design view
• Use comparison operators and wildcards to make queries more flexible
• Verify query results using business knowledge
34
Succeeding in Business with Microsoft Access 2013 35
Level 2 Objectives:Creating More Complex Queries
• Design queries that compare data from more than one table
• Refine table relationships by specifying the join type
• Perform calculations in queries• Customize queries and their results
Succeeding in Business with Microsoft Access 2013 36
Succeeding in Business with Microsoft Access 2013 37
Using Queries to Find Duplicate Records
• Duplicates Query Wizard– Searches for duplicate values in fields– Improves business operations– Designed to identify records that contain same
information in particular field
Succeeding in Business with Microsoft Access 2013 38
Using Queries to Find Unmatched Records
• Find Unmatched Query Wizard– Compares records in two specified tables or
recordsets – Finds all records in one table or query that have
no related records in second table or query– Requires that two tables being compared have
common field
Succeeding in Business with Microsoft Access 2013
Limiting the Records in the Query Results
• Limiting results to only a few records often aids analysis
• Top and Bottom Values– Set a sort order for the field– Descending to display the records with the highest
values– Ascending to display the records with the smallest
values
39
Succeeding in Business with Microsoft Access 2013 40
Succeeding in Business with Microsoft Access 2013
Using Parameter Values in Queries
• Parameter values – Phrase usually in form of a question or instruction – Enclosed in square brackets– Serves as prompt to user to enter value– Example• [Enter a job ID:]
41
Succeeding in Business with Microsoft Access 2013 42
Succeeding in Business with Microsoft Access 2013 43
Analyzing Data from More than One Table
• Data from more than one table required to answer question– Combine records from two or more tables – Display only information needed
• Work in Design View to specify criteria for selecting records from multiple tables
• Lines between tables link primary key to foreign key field– Primary key designated with 1– Foreign key designated with ∞
Succeeding in Business with Microsoft Access 2013 44
Analyzing Data from More than One Table (cont’d.)
• Join tables– Linking of tables using primary and foreign keys– Established relationship – Or
• Each table shares field with same or compatible data type • One join field primary key
• If tables do not include fields that can be joined– Add one or more extra tables or queries – Link tables that contain the data
Succeeding in Business with Microsoft Access 2013 45
Analyzing Data from More than One Table (cont’d.)
• Use queries as source of underlying data for another query in place of one or more tables
• Create queries based on more than one object– Should not use any table or query that does not
have common field with at least one of the other tables or queries
– Otherwise Access displays every combination of records between two tables
Succeeding in Business with Microsoft Access 2013 46
Refining Relationships with Appropriate Join Types
• Inner join– Displays all records in one table that have
corresponding values in common field in another table
– Records must match before being displayed in query results
• Outer join– Displays all records of one table
• Regardless of whether corresponding record is stored in related table
Succeeding in Business with Microsoft Access 2013 47
Figure 3.34: Inner join
Succeeding in Business with Microsoft Access 2013 48
Succeeding in Business with Microsoft Access 2013 49
Figure 3.36: Right outer join
Succeeding in Business with Microsoft Access 2013 50
Refining Relationships with Appropriate Join Types (cont’d.)
• Outer join types– Left– Right
• Use Join Properties dialog box– To change join type– By default, tables are related using inner joins– Options for outer joins
Succeeding in Business with Microsoft Access 2013 51
Using Logical Operators to Specify Multiple Conditions
• Logical operators– Test values that can only be true or false
• Place conditions in separate fields in same criteria row of design grid– All conditions in row must be met to select record
• NOT logical operator – Excludes values that don’t meet criterion
Succeeding in Business with Microsoft Access 2013 52
Succeeding in Business with Microsoft Access 2013
Performing Calculations with Queries
• Any information derived from fields in table or query should be calculated in query – Rather than included as data in table
• Calculation types– Predefined
• Compute amounts for groups of records or for all records combined in query
– Custom• Perform numeric date and text computations on each record • Using data from one or more fields
53
Succeeding in Business with Microsoft Access 2013
Calculating Statistical Information
• Aggregate functions– Mathematic and statistical operations – Apply to records that meet query’s selection
criteria
54
Succeeding in Business with Microsoft Access 2013 55
Succeeding in Business with Microsoft Access 2013 56
Figure 3.43: Using aggregate functions in a query
Succeeding in Business with Microsoft Access 2013
Creating Calculated Fields in a Query
• Expression – Arithmetic formula for calculation– Use standard arithmetic operators– Use parenthesis for complex expressions
• Calculated field– Add to query design grid– Type expression
• Expression Builder– Build complex expressions
57
Succeeding in Business with Microsoft Access 2013 58
Creating Calculated Fields in a Query (cont’d.)
• Function– Performs standard calculation– Returns value
• Date()– Provides today’s date
• Field properties– Change format and number of decimal places for
calculated field
Succeeding in Business with Microsoft Access 2013 59
Succeeding in Business with Microsoft Access 2013
Concatenating in Queries
• Concatenation– Combining contents of two or more fields– Operator• &
– Example• Name [EmpFirst]& " " & [EmpLast]
60
Succeeding in Business with Microsoft Access 2013
Level 2 Summary
• Use queries to select from more than one table• Join types– Inner– Right outer– Left outer
• Calculated field types– Predefined– Custom
61
Succeeding in Business with Microsoft Access 2013
Level 3 Objectives: Exploring Advanced Queries and Queries Written in Structured
Query Language
• Calculate and restructure data to improve analysis
• Examine and create advanced types of queries• Make decisions in a query using the
immediate IF (IIF) function• Develop queries using SQL
62
Succeeding in Business with Microsoft Access 2013 63
Analyzing Query Calculations
• More advanced queries– Crosstab query• Most useful for preparing data for further analysis
– Action queries• Change or move many records in one operation
– Four types of action queries:• Append, update, delete, and make-table
Succeeding in Business with Microsoft Access 2013 64
Analyzing Query Calculations (cont’d.)
• Crosstab queries – Special type of totals query – Perform aggregate function calculations on values
of one database field – Determine exactly how summary data appears in
results– Calculate and restructure data • Analyze it more easily
– Work especially well with time-series data
Succeeding in Business with Microsoft Access 2013
Creating a Crosstab Query
• To create:– Use Design View• Start with select query that includes numeric values or
summary calculations– Use the Crosstab Query Wizard• Guides you through the steps• Shows samples of how the crosstab results will look
65
Succeeding in Business with Microsoft Access 2013 66
Succeeding in Business with Microsoft Access 2013
Modifying Data Using Queries
• Action queries – Modify data in table – Add records to or delete records from table – Create new table
• Backup data before using action query
67
Succeeding in Business with Microsoft Access 2013 68
Succeeding in Business with Microsoft Access 2013 69
Succeeding in Business with Microsoft Access 2013
Archiving Data with Make-table Queries
• Make-table query – Creates table from some or all of the fields and
records in existing table or query– Access does not delete selected fields and records
from existing table
70
Succeeding in Business with Microsoft Access 2013 71
Adding Records to Tables with Append Queries
• Append query – Select records from one or more tables by setting
criteria – Add those records to end of another table– Selected records also remain in original tables – Table to which records added must already exist– Can bring data from another source into database
Succeeding in Business with Microsoft Access 2013
Removing Records from Tables with Delete Queries
• Delete query – Removes information from table – Based on specified criteria– All records meeting criteria permanently removed
• Create select query first– Convert to delete query
• Cascading deletes
72
Succeeding in Business with Microsoft Access 2013
Updating Data with an Update Query
• Update query – Changes values of data in one or more existing
tables– Create select query first• Change type to update query
73
Succeeding in Business with Microsoft Access 2013 74
Making Decisions in Queries
• IF statement– Tests condition – Takes one action if condition true – Takes another action if condition false
• IIF function– Make IF decision– Format• IIF(condition to test, what to do if true, what to do if
false)
Succeeding in Business with Microsoft Access 2013 75
Customizing Queries Using Structured Query Language
• Access designed as database management system (DBMS) for: – Small businesses – Or departments within large businesses
• Structured query language– Common query language of most DBMSs– Use to query/update/manage relational databases
• Create query in Design View– Access translates entries and criteria into SQL
statements
Succeeding in Business with Microsoft Access 2013 76
Customizing Queries Using Structured Query Language (cont’d.)
• View statements by switching from Design view to SQL view
• SELECT statement defines: – What data query should retrieve from database – How it should present data
Succeeding in Business with Microsoft Access 2013 77
Exploring the Components of an SQL Query
• Keywords – Use to construct SQL statements
• Most developers place each statement on separate line – To make SQL code easy to read
Succeeding in Business with Microsoft Access 2013 78
Succeeding in Business with Microsoft Access 2013 79
Creating a Union Query Using SQL
• Union query– Combine, or unite, the results from two or more
select queries
Succeeding in Business with Microsoft Access 2013
Level 3 Summary
• Crosstab and Action queries• IFF function• SQL– Use SQL view to edit SQL directly
80
Succeeding in Business with Microsoft Access 2013
Chapter Summary
• Queries retrieve data from one or more tables– Action queries update data– Perform calculations– Make decisions using IIF function
• SQL– Used to interact with relational databases– Use SQL view to view/edit SQL statements
generated by Access
81
Recommended