Professional Documents
Culture Documents
Unit 6 - Extracting Information From A Relational Database Using Queries
Unit 6 - Extracting Information From A Relational Database Using Queries
6
Extracting Information from
a Relational Database Using
Queries
Source:http://tinyurl.com/zsm25z6
Overview
3. Run a Query;
5. Outline the use of calculated fields, parameter queries and aggregate functions;
Required Resource
Miller, Lisa. (2008). MIS Cases: Decision making with application software (3rd
Edition). Pearson Education Inc., Upper Saddle River, New Jersey
Additional Resources
Donalds, C. and Henry, J. (2011). Solving managerial problems with spreadsheets
and databases
Introduction
Software Databases are able to store millions of transactional and other records on
behalf of a business. The voluminous nature of this raw data makes it difficult to
use when making many operational, tactical and strategic decisions. For such data to
become effective and good information it must be concise and relevant. Queries allow
you to extract relevant information from available data. This session will show you
how to create, configure and run your own simple custom queries in order to satisfy
specific informational needs.
Query
A Query is essentially a request made by you to interact with the records stored within
the tables of a Database Solution. This interaction could be in the form of a request
to retrieve information, to add, change or delete records or some other action on the
data/records stored within a Database.
You should consider using Queries whenever you wish to extract, add, change, or
delete records from your database. Queries can perform their configured tasks on
individual records, subsets of a table or tables, entire tables or even multiple tables at
a time.
Once a query is built it must be executed or “run”; this essentially means that the
request is submitted to the Database software and, provided that the query is valid,
the software fulfils the request by completing the tasks and providing the user with
the results of the Query. These results may be used as the source of data for a Report.
Creating a Query
A Query may be created using one of the following options:
• Design View
• SQL View
Figure 6.1: New Query Wizard Dialog Figure 6.2: Simple Query Wizard Dialog
Box
Each question/response step configures a part of the final Query. Once complete the
Query may be modified and/or executed. While this is the simplest approach it gives
the user the least control over the Query configuration.
Design View
This is the most common approach to building and configuring a Query. This approach
strikes a good balance between ease-of-use for the average not-extremely-technical
user and granular control over the configuration of the Query. It provides a graphical
user’s interface that allows users to easily create, configure and modify a Query. As
such this approach is ideal for business management professionals and will be the
approach used throughout this unit.
SQL View
This approach allows users to build and configure a Query using the actual
programming query commands natively understood by Database software. Though
not extremely difficult, this approach requires more technical skill than the first two
approaches. What this technique loses with respect to ease-of-use it makes up for in
the level of control afforded to the user when configuring the Query. The first two
approaches would automatically generate these Query commands based on the options
chosen. This approach requires you to write them yourself. This topic is explored in
significantly more detail within the following recommended texts.
SELECT Query
SELECT Queries are those used to retrieve, extract, synthesise and compile information
from the myriad of tables and records found within a given Database solution. These
queries do not change, delete or update records stored within the database. You must
create a single-table query whenever you need to retrieve some portion of the data/
fields and/or subset of the records of a single table. You must create a multi-table
Query whenever you need to retrieve data items/fields from records scattered across
multiple tables. These types of queries are explored in further detail in upcoming
activities.
ACTIVITY 6.1
SELECT Query: Single-Table (20 minutes)
Instructions:
Task A: Using the links provided, view the video tutorial on building
single-table SELECT Queries.
●● Miller, Lisa. (2008). MIS Cases: Decision making with application software
(3rd. Edition). Pearson Education Inc., Upper Saddle River, New Jersey
Download the Unit 8 copy of the Salon Database (available on the course
page) and examine the tables found within (both structure and content).
Using the Salon Database you are to:
Optional
Modify the query so that it only returns the records for persons living in
the 94115 zip code. Once modified you are to run the updated query and
view the results.
Note: A link to the Learning Activity 6.1 Task B video solution will be
provided on the course page.
ACTIVITY 6.2
SELECT Query: Multiple Tables (20 minutes)
Instructions:
Task A: Using the links provided, view Part 1 and Part 2 of the video
tutorial on building Multi-Table SELECT Queries.
Note: A link to the Learning Activity 6.2 Task B video solution will be
provided on the course page.
In Session 6.1 we learnt the purpose and usage of database Queries, explored how
to create and configure SELECT Queries and considered how the results of such a
Query may be used to fulfil some business need. The knowledge and skill developed
in this unit will enable you to create and use your own custom queries to support
future decision-making. The next session will further refine your knowledge and skills
in creating, configuring and using SELECT Queries to better address a stakeholder’s
informational needs.
Introduction
Database users must be able to specify what records should be returned and what
records should be ignored by Queries to provide the information required to support
management decisions. Query criteria allow users to specify these details. This session
will show you how to modify Queries to be more effective by teaching you how to
define Query criteria and configure Query sort option.
Modify a Query
As demonstrated in Session 6.1, when you open an existing Query it is automatically
run and its query results are displayed within something similar to a table. This is
referred to as the Datasheet view of the Query. To modify your query you must first
switch to the Design view, the view you use when creating or editing Queries. The
following section describes two ways to switch to the Design view.
1. Locate the Query you would like to edit. Right-click on the Query. Click Design
view.
2. Locate the Query you would like to edit. Run the Query. Move to the Home tab
of the Ribbon, click the View button to make the View drop-down menu visible,
select Design View.
ACTIVITY 6.3
Sorting Queries (20 minutes)
Instructions:
Visit the webpage via the appropriate link (provided below) to learn how to
sort a Query.
uu http://www.gcflearnfree.org/access2010/more-query-design-options/3/
For Microsoft Access 2013 users:
GCFLearnFree.org. (2015, October 7). Access 2013: More Query Design
Options. Retrieved June 2016, from
uu http://www.gcflearnfree.org/access2013/more-query-design-options/2/
ACTIVITY 6.4
Defining Criteria (20 minutes)
Instructions:
Task A:
Using the links provided, view Parts 1 to 3 of the video tutorial on
demonstrating how to define and use Query criteria. You are encouraged
to make your own notes.
Part 1
Office Videos. (2013, June 11). Training: Use query criteria in Access 2013:
The basics tutorial - Video 1 of 4 [Video file].Retrieved June 2016, from
uu http://www.youtube.com/watch?v=AT9vs5ksF3I
Task A:
The staff of Timeka’s Tanning Salon, Inc. needs you to build a number
of queries to support its operations. Using the Unit 8 copy of the Salon
Database (available on the course page) engage in the activities below:
In Session 6.2 we learned how to define the criteria of a Query and how such may be
useful when attempting to retrieve information using Queries. This will allow you
to refine Queries to provide the right information needed to support a management
decision. The upcoming session will introduce you to Database Reports and
demonstrate how to use the results of a Query as the source of data for a management
report.
Introduction
In earlier sessions we learnt how to create and configure simple Queries to support
management decision making needs. Though useful, these initial Queries only allowed
a user to retrieve information from one or more tables (possibly based upon some
fixed criteria(s) specified at the time the Query was created).
In the real world, business stakeholders typically require more flexible and powerful
ways of extracting and producing meaningful information. Business stakeholders often
find it necessary to 1) perform calculations on fields/data items found across different
tables of a database, 2) configure variable criteria values at Query run time and 3)
utilise aggregate Functions to derive summary information from a group of records.
Database Software like Microsoft Access provides Managers with the ability to create
more advanced Queries to address these complex informational requirements.
This session will introduce you to the Advanced Query options. It will first show you
how to create and use calculated fields within a Query so that you may be able to
derive or produce information based upon some business rules. Next, it will introduce
you to a more flexible type of Query known as the Parameter Queries. These types
of Queries should be used whenever you wish to derive specific information using
variable criteria values at Query run time, i.e. values that may change each time we
wish to run the Query. Throughout the learning activities found within this session
you will learn how to create and use these Parameter Queries. Finally, you will explore
options to enhance the utility of Queries through the use of Aggregate Functions.
Aggregate Functions allow users to derive summary information from a group
of records. Aggregate or summary information, such as sums, averages, minimum
and maximum values, are usually quite useful to management stakeholders. Where
individual records provide a detailed view useful for many operational decisions,
a management user may find aggregate information, derived from these individual
records, to be more usable when they attempt to make decisions of a more tactical or
strategic nature.
ACTIVITY 6.6
Calculated Field (20 minutes)
Instructions:
Task A:
Proceed to the Database Glossary section of your course text (see below):
Miller, Lisa. (2008). MIS Cases: Decision making with application software
(3rd. Edition). Pearson Education Inc., Upper Saddle River, New Jersey
Read the Calculated Field discussion and example found on pages 359-
360 and post responses to the following in the Unit forum:
Task B:
Watch the video tutorial and example on creating Queries with Calculated
Fields at the link below.
Visit the webpage via the appropriate link (provided below) to learn more
about Calculated Fields within Tables.
For Microsoft Access 2010 users:
GCFLearnFree.org. (2015, February 19). Access 2010: Tables: How to
Create Calculated Fields and Totals Rows. Retrieved from:
uu http://www.gcflearnfree.org/access2010/tables-how-to-create-
calculated-fields-and-totals-rows/1/
uu http://www.gcflearnfree.org/access2013/creating-calculated-fields-
and-totals-rows/1/
The Learning Activity below gives you the opportunity to practice what you have
learnt throughout this Session.
Begin this Learning Activity by reviewing the details of Case 15: Granny
Joan’s Cookies found in your course text (see below):
Miller, Lisa. (2008). MIS Cases: Decision making with application software
(3rd. Edition). Pearson Education Inc., Upper Saddle River, New Jersey
Note, a partially completed solution for this case has been prepared and
uploaded to the course page for your use in this Learning Activity. Download
the Unit 10 copy of the Granny Joan’s Cookies Database (available on the
course page ) and examine the tables found within (both structure and
content).
You are to follow the business rules defined within the case scenario
narrative to determine the formula for the selling price calculated field.
Note that gross income = selling price – cost price.
When you are finished you are to run the Query to derive the result.
ACTIVITY 6.9
How to Create a Parameter Query (20 minutes)
Instructions:
Visit the webpage via the appropriate link (provided below) to learn how to
create and use a Parameter Query.
uu http://www.gcflearnfree.org/access2010/queries-how-to-create-a-
parameter-query/1/
uu http://www.gcflearnfree.org/access2013/creating-a-parameter-
query/1/
This Learning Activity gives you the opportunity to practice what you have
learnt throughout this Session.
Begin this Learning Activity by reviewing the details of Case 15: Granny
Joan’s Cookies found in your course text (see below):
Miller, Lisa. (2008). MIS Cases: Decision making with application software
(3rd. Edition). Pearson Education Inc., Upper Saddle River, New Jersey
Note, a partially completed solution for this case has been prepared
and uploaded to the course page for your use in this Learning Activity.
Download the copy of the Granny Joan’s Cookies Database (available on
the course page ) and examine the tables found within (both structure and
content).
To better manage the tracking and reconciliation of sales and income the
administrative assistant, Ms. Kelly, needs a quick and easy way to retrieve
the list of student sellers within a given grade.
You are to create a Parameter Query called qryStudentsInGrade. The
Query must prompt the user to enter a parameter for the student grade.
The Query will then retrieve the details of the student sellers within the
grade provided. Details to be displayed within the result set include the
fields SellerID, SellerFirstName, SellerLastName and Grade. When you
are finished you are to run the Query to derive the result and answer the
Knowledge Check following this Learning Activity.
Task A:
Proceed to the Database Glossary section of your course text (see below):
Miller, Lisa. (2008). MIS Cases: Decision making with application software
(3rd. Edition). Pearson Education Inc., Upper Saddle River, New Jersey
Read the Aggregate Function definition and example found on page
354. From the definition and the example you should have an idea of the
potential usefulness of incorporating these functions within Queries.
As you proceed to Task B you are to consider how the available aggregate
functions (including COUNT, SUM, AVG, MIN and MAX) may be used to
support management decisions. Note, a Query that makes use of the
SUM aggregate function may sometimes be referred to as a Totals Query.
Task B:
Visit the webpages via the appropriate links (provided below) to learn more
about using aggregate functions within Queries.
For Microsoft Access 2010 users:
Part 1
GCFLearnFree.org. (2015, February 19). Access 2010: More Query
Design Options. Retrieved from:
uu http://www.gcflearnfree.org/access2010/more-query-design-options/5/
Part 2
GCFLearnFree.org. (2015, February 19). Access 2010: More Query
Design Options. Retrieved from:
uu http://www.gcflearnfree.org/access2010/more-query-design-options/6/
Part 1
GCFLearnFree.org. (2015, October 7). Access 2013: More Query Design
Options. Retrieved, from:
uu http://www.gcflearnfree.org/access2013/more-query-design-options/4/
Part 2
GCFLearnFree.org. (2015, October 7). Access 2013: More Query Design
Options. Retrieved from:
uu http://www.gcflearnfree.org/access2013/more-query-design-options/5/
Task C:
Watch the video tutorial and example on creating Queries with Calculated
Fields and Aggregate Functions at the link below.
Phillips, R. (2012, April 26). Create Queries with Calculated Fields and
Aggregate Functions [Video file]. Retrieved from:
The Learning Activity below provides the opportunity to practice what you have
learnt in the earlier parts of this Session.
1. Based on gross sales, which grade has sold the most cookies? Identify
grade level and the collected income.
2. Based on gross sales, which student has sold the most cookies?
4. Which student has sold all the cookies that they have checked out?
Task B
Using the links provided you are to complete the online tutorial on building
Designing Multi-Table Queries. This tutorial should help to clarify what you
learnt in Task A above. Be sure to attempt the challenge found at the end
of the tutorial.
GCFLearnFree.org. (2015, October 7). Access 2013: Designing a Multi-
Table Query. Retrieved from:
uu http://www.gcflearnfree.org/access2013/designing-a-multitable-
query/1/
Task C
Watch the video tutorial and example on Basic Joins in Access found at
the link below. This should give you a practical appreciation for what you
learnt within Task A and Task B above.
Phillips, R. (2013, June 5). Basic Joins in Access Queries [Video file].
Retrieved from:
Introduction
Tables and Queries provide users with an easy-to-use mechanism for perusing the
data and information in a Database while they are physically in front of a PC. These
mechanisms fall short however when attempting to prepare printed copies of this
data and information to use or share with persons while away from a PC. Reports are
database objects, similar to Tables and Queries, specifically designed to address the
limitations discussed. Reports provide the flexibility to format, group and summarise
information in a professional manner more suitable for printing and distribution to
management stakeholders. In this session we will learn how to create Reports using
the contents of a Table or the results of a Query as the data source.
ACTIVITY 6.14
Create, save, modify, print and export a Report (10 minutes)
Instructions:
Visit the webpage via the appropriate link (provided below) to learn how to
create, modify and print a Report.
For Microsoft Access 2010 users:
GCFLearnFree.org. (2015, February 19). Access 2010: Creating Reports.
Retrieved June 2016, from
uu http://www.gcflearnfree.org/access2010/creating-reports/1/
For Microsoft Access 2013 users:
GCFLearnFree.org. (2015, October 7). Access 2013: Creating Reports.
Retrieved June 2016, from
uu http://www.gcflearnfree.org/access2013/creating-reports/1/
In this session we reviewed creating and using reports to display information retrieved
from a Query. This helps you to use simple reports to present data and information in
a consistent and professional manner.
Unit 6 Summary
In this unit we examined how queries and criteria may be used to extract information
from the database and present said information in a form more suitable to business
stakeholders. These skills will enable you to be respond to the dynamic information
needs of business stakeholders and provide the information needed to support the
decision-making effort.
Miller, Lisa. (2008). MIS Cases: Decision making with application software (3rd
Edition). Pearson Education Inc., Upper Saddle River, New Jersey
Office Videos. (2013). Training: Use query criteria in Access 2013: The basics tutorial
- Video 1 of 4. Retrieved from: http://www.youtube.com/watch?v=VjQ_
jVHGaGQ
Office Videos. (2013) Training: Use query criteria in Access 2013: Using AND and
OR with multiple criteria - Video 2 of 4. Retrieved from: http://www.youtube.
com/watch?v=eFPU9gyZYtw
Office Videos. (2013). Training: Use query criteria in Access 2013: Using NOT, IN,
LIKE, BETWEEN - Video 3 of 4. Retrieved from: http://www.youtube.com/
watch?v=AT9vs5ksF3I