Exploring Microsoft Office 2013: Tables and Queries in Relational Databases
Exploring Microsoft Office 2013: Tables and Queries in Relational Databases
VOLUME 1
by Mary Anne Poatsy, Keith
Mulbery, Lynn Hogan, Amy
Rutledge, Cyndi Krebs, Eric
Cameron, Rebecca Lawson
Chapter 2
Tables and Queries in
Relational Databases
11
CREATING ACCESS RELATIONSHIPS
12
CREATING ACCESS RELATIONSHIPS
13
CREATING ACCESS RELATIONSHIPS
14
CREATING ACCESS RELATIONSHIPS
15
CREATING A SINGLE-TABLE QUERY
QUERY WIZARD
1.Click the CREATE tab.
2.Click Query Wizard in the Queries group.
3.The New Query wizard starts, select Simple
Query Wizard then click OK
4. Simple Query Wizard dialog box appears. In
the box labelled Tables/Queries select Table:
tblContact from the drop down menu.
5. Enter qryQuery01 as the name for the query
16
QRYQUERY01
17
QRYQUERY01
18
CREATING A SINGLE-TABLE QUERY QUERY
DESIGN
19
QUERY DESIGN VIEW
20
QUERY DATASHEET VIEW
21
SINGLE TABLE QUERY
1. Create a single table query using query
design that display all contact information of
“Ali Baba”.
2. Save your query as qryQuery02.
22
QRYQUERY02
23
QRYQUERY03A
24
QRYQUERY03A
25
QRYQUERY03B
1. Create a select query titled qryQuery03B,
based on the tblOrder table, which will list all
the fields in the orders table.
26
QRYQUERY03B
27
QRYQUERY03C
1. Modify the query to show the totals VALUE
for each ORDER TYPE only using the
‘Group by’ and ‘Total’ functions. Sort the
results in DESCENDING order based on its
total VALUE. Your query and dynaset should
look like the ones below. Save your query as
qryQuery03C.
28
QRYQUERY03C
29
QRYQUERY03D
1. Find the average number of books ordered.
30
QRYQUERY03D
31
QRYQUERY3E
1. Find the order for books with the lowest
value. Save the query as qryQuery3E.
32
QRYQUERY3E
33
QRYQUERY03F
1. Add the tblInstitution table, then add the fields
Sector and Enrolment Size.
2. Click on the Total button on the toolbar. A
total row appears in the QBE grid.
3. In the Sector field choose Group By from the
total menu. In the Enrolment Size field choose
Avg (average) from the total menu. Save as
qryQuery03F.
34
QRYQUERY03F
35
MULTITABLE QUERIES
• Contains two or more tables
• Uses related tables
• Similar to creating single-table query
36
MULTITABLE QUERIES
1. In the Show Table window click on tblOrder, then click on add to add
the table to the query. Do the same for tblInstitution, then click on Close.
2. A query design window appears. Add the following fields by double
clicking on the field name.
• - tblOrder.Order Number (i.e. the order number field from the tblOrder
table)
• - tblOrder.Institution Code
• - tblInstitution.Institution Code
• - tblInstitution.Institution Name
• - tblInstitution.Enrollment Size
3. In the Criteria row for Enrolment Size column, type >5000, sorted in
ascending order. Save as qryQuery04A.
37
QRYQUERY04A
38
QRYQUERY04B
1. Create a query titled qryQuery04B that finds
the largest number of books ordered by a single
institution. This means we want to know what is
the largest number of books that a particular
institution has ordered if any.
2. Include Institution Code, Institution Name and
Book Quantity from tblOrder and tblInstitution
in your query as shown below.
39
QRYQUERY04B
40
QRYQUERY04C
1. Create qryQuery04C that is based on tblOrder
and tblInstitution.
2. Select Institution Code, Institution Name, Order
No and CD Renewal as the fields for the query.
3. We’d like to find all the CD orders with renewal
dates before 01-Jan-2012. Include this criteria ( <
1/1/2012 ) in the criteria for CD Renewal.
41
QRYQUERY04C
42
QRYQUERY04D
1. Create a query that retrieves records from
tblContact, tblInstitution and tblOrder to obtain
the Contact Name from College or University
Institutions with TOTAL order values higher
than 50,000.
43
QRYQUERY04D
44
QRYQUERY04E
1. Now, we’d like to create a query that does some basic
calculation for us. Assuming that the sales team at SMS
gets a 20% commission for every order they get from
institutions. We’d therefore like to know how much
commission they receive for each order made.
2. Add two tables tblInstitution and tblOrder to
qryQuery4E. Select Order No, Institution Code,
Institution Name and Value.
3. Create a new field called ‘Commission’. This is the title
that will be displayed for the field.
4. Next, enter the expression for the field: [tblOrder.Value]
* 0.2 45
QRYQUERY04E
46
COPYRIGHT
All rights reserved. No part of this publication may be reproduced, stored in a retrieval
system, or transmitted, in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise, without the prior written permission of the
publisher. Printed in the United States of America.