Queries Requiring Two Tables



Similar documents
Getting Started with Access 2007

Unit 10: Microsoft Access Queries

Tutorial 3. Maintaining and Querying a Database

Microsoft Office 2010

Les s on Objectives. Student Files Us ed

Instructions for Creating an Outlook Distribution List from an Excel File

Lab 2: MS ACCESS Tables

Building Queries in Microsoft Access 2007

Lesson 3 - Processing a Multi-Layer Yield History. Exercise 3-4

Working together with Word, Excel and PowerPoint

Sample- for evaluation only. Introductory Access. TeachUcomp, Inc. A Presentation of TeachUcomp Incorporated. Copyright TeachUcomp, Inc.

Access 2010: Creating Queries Table of Contents INTRODUCTION TO QUERIES... 2 QUERY JOINS... 2 INNER JOINS... 3 OUTER JOINS...

Microsoft Access Rollup Procedure for Microsoft Office Click on Blank Database and name it something appropriate.

Microsoft Access 2010 Part 1: Introduction to Access

Produced by Flinders University Centre for Educational ICT. PivotTables Excel 2010

Introduction to Microsoft Access 2003

Creating QBE Queries in Microsoft SQL Server

Tutorial 3 Maintaining and Querying a Database

Create a New Database in Access 2010

Working with SQL Server Integration Services

Access Tutorial 3 Maintaining and Querying a Database. Microsoft Office 2013 Enhanced

A database is a collection of data organised in a manner that allows access, retrieval, and use of that data.

Microsoft Excel 2013: Using a Data Entry Form

MICROSOFT OUTLOOK 2011 READ, SEARCH AND PRINT S

Microsoft Office 2010

Advanced Database Concepts Using Microsoft Access

MS Access Lab 2. Topic: Tables

MICROSOFT ACCESS 2003 TUTORIAL

Creating Calculated Fields in Access Queries and Reports

Access 2007 Creating Forms Table of Contents

Learn how to create web enabled (browser) forms in InfoPath 2013 and publish them in SharePoint InfoPath 2013 Web Enabled (Browser) forms

MS Excel Template Building and Mapping for Neat 5

Microsoft Office 2007 Orientation Objective 1: Become acquainted with the Microsoft Office Suite 2007 Layout

Creating and Using Databases with Microsoft Access

Using Microsoft Access

Use Find & Replace Commands under Home tab to search and replace data.

Creating and Formatting Charts in Microsoft Excel

Database Applications Microsoft Access

Excel Reports and Macros

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Creating a Participants Mailing and/or Contact List:

Microsoft Access Creating Filters and Tables

for Sage 100 ERP Business Insights Overview Document

INTRODUCTION TO DATABASES USING MICROSOFT ACCESS

Databases in Microsoft Access David M. Marcovitz, Ph.D.

MS Access. Microsoft Access is a relational database management system for windows. Using this package, following tasks can be performed.

Using Spreadsheets, Selection Sets, and COGO Controls

IS 312, Information Systems for Business Database Project in Access

Joins Joins dictate how two tables or queries relate to each other. Click on the join line with the right mouse button to access the Join Properties.

Monthly Payroll to Finance Reconciliation Report: Access and Instructions

Lesson 07: MS ACCESS - Handout. Introduction to database (30 mins)

Using Microsoft Access

Microsoft Access 2010 Overview of Basics

Microsoft Office Access 2007 Basics

EXCEL Using Excel for Data Query & Management. Information Technology. MS Office Excel 2007 Users Guide. IT Training & Development

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

Set Up Setup with Microsoft Outlook 2007 using POP3

Querying a Database Using the Select Query Window

IST 195 Lab 11: MS Access

Microsoft Access 2010: Basics & Database Fundamentals

Excel will open with the report displayed. You can format and/or save the report as desired.

Instructions for applying data validation(s) to data fields in Microsoft Excel

TAMUS Remote Desktop Setup For BPP SQL & Alva

Completing Baseline s Site Survey Request Form

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Introduction to Microsoft Access 2010

MICROSOFT ACCESS STEP BY STEP GUIDE

Task Force on Technology / EXCEL

Symantec Enterprise Vault

BAT Smart View for Budget Users. Miami-Dade County. BAT Smart View Training Activity Guide

Microsoft Access 2010 handout

Introduction to Microsoft Access 2013

In This Issue: Excel Sorting with Text and Numbers

Viewing and Troubleshooting Perfmon Logs

Database Forms and Reports Tutorial

Analyzing Excel Data Using Pivot Tables

Basic Pivot Tables. To begin your pivot table, choose Data, Pivot Table and Pivot Chart Report. 1 of 18

Word 2010: Mail Merge to with Attachments

Using an Access Database

Access Queries (Office 2003)

Creating a Database in Access

MS WORD 2007 (PC) Macros and Track Changes Please note the latest Macintosh version of MS Word does not have Macros.

User Services. Intermediate Microsoft Access. Use the new Microsoft Access. Getting Help. Instructors OBJECTIVES. July 2009

Getting Started with Excel Table of Contents

BEx Analyzer (Business Explorer Analyzer)

Crystal Reports Payroll Exercise

Microsoft Word Track Changes

Access Tutorial 1 Creating a Database. Microsoft Office 2013 Enhanced

Build an ArcGIS Online Application

Database File. Table. Field. Datatype. Value. Department of Computer and Mathematical Sciences

MICROSOFT ACCESS TABLES

Introduction to Microsoft Access 2007

A guide to bulk deposit submissions

Excel 2003: Ringtones Task

Introduction to Microsoft Access XP

European Computer Driving Licence

Agency Manager Professional Software Manual

Chapter 5. Microsoft Access

Advanced Presentation Features and Animation

Transcription:

Queries Requiring Two Tables Significant in the PayMaster database is the use of a separate table to list the towns employees reside (live.) By using a separate table for commonly entered data, the Relational Database minimises the potential for errors when entering data. To perform a search/query that requires information from more than one table we simply need to include the separate tables in our query. For example: If we are to ask the database for the average wage of people from Veitongo then we need data from both the table Employee as well as the table Town. From the table Town we get the town Veitongo and match it to the Pay Rate for each employee. 1 Start a New Query by going to the Queries object, and clicking on New. 2 Specify that we want to use Design View for our New Query. 3 When the Show Table dialog shows up, add both the [Employee] tableand the [Town] table before closing the dialog. 4 Our query requires the [Town] and [Pay Rate] so we double-click on these fields so they show up on the bottom pane. 5 We only need Veitongo in the Criteria for the [Town] field, we type in Veitongo. 6 To get the average [Pay Rate] we would use the Totals (go to the Totals Tool item, or the menu View Totals and specify in the drop-down list box that we want the Average (avg). 7 A check of the results with DataSheet view should reveal a number such as MS Access Compound Queries Page 1

listed below. 2.22655172234979 Making a Calculation What we have calculated above is the average of [Pay Rate] which is good, but we actually need to find the average wage. The wage is found by multiplying the [Pay Rate] and the [Weekly Hours] We can find the average after we have made the calculation. 1 So let s open up a new query, have both tables specified for the query (just as we have made for the previous query.) 2 Specify you want a column each for [Name], [Surname], [Weekly Hours], and [Pay Rate] 3 On the fifth column, where no field has been currently selected click on the first cell, right-click on the field-row. You will get the menu shown to the right, and we need to take a look at the Zoom command so select that command. (You can also get to Zoom by pressing the Shift+F2 key-combination.) 4 You have a dialog box for entering a formula. Enter the Formula: Total Pay : [Weekly Hours] * [Pay Rate] 5 Select OK to accept the formula 6 Click on the DataSheet View to see what our query gives us. MS Access Compound Queries Page 2

Special Notes on Formula Entry: The new field name, column header (eg. Total Pay) must be followed directly by a colon. When we use fields inside a calculation we use square brackets [ ] to let Access know that these are special variables referring to fields in the table. Make sure that you have typed the field names in correctly, and that you are using square brackets. The Weekly Hours field is specified in square brackets to tell Access to grab information that is in this field. Colon symbol The Pay Rate field in square brackets tells Access to grab information from this field. Multiplication symbol Name that will be displayed as the Header of the Column. Must be the first item and be followed by a colon Finalising Our Query Remember what we actually want is the Average wage for people from Veitongo. Now we know how to look for only people in Veitongo, and we know how to calculate the wage, let s find the average wage for Veitongo. 1 Create a new query with both tables (since we need information from both tables) 2 Specify you want a column each for [Name], [Surname], [Weekly Hours], [Pay Rate], and [Town] (note we are including Town in this query) 3 In the column for [Town] specify the criteria Veitongo 4 For the sixth place set our formula for calculating the wages 5 Check with the Datasheet view that you have collected only Total Wages for Veitongo 6 Save the Query as qryveitongo Pays (this is important for the next part) 7 Start a New Query, select Design View and the Show Table dialog box shows up. MS Access Compound Queries Page 3

Select the Queries Tab to show saved queries Queries saved in the database are listed here 8 We need to calculate the average of the Total Pay which is not in any of the tables, but in the query we just saved. Select the Queries Tab, and we should see on the list the saved query qryveitongo Pays. 9 Select qryveitongo Pays, add itandthenselect close to close the dialog box 10 We only need one field, the [Total Pays] so we double-click on that 11 We need to the average of Total Pays, so we need to open the Totals option by clicking on the Totals tool, or selecting View Totals from the menu. 12 With the Totals row showing, we select the average function (AVG) 13 Use the Datasheet view to verify that your average wage for Veitongo is 46.293792932 Total Queries Sometimes you aren't interested in each and every row in your table. You'd rather see totals of different groups of data. For example, you might want the total contract amount for all clubs in a particular state. Or you might want to know the average of all sales for each month in the last year. To get these answers, you need a total query. To calculate totals within any query, click the Totals button on the toolbar in Design view to open the Total row in the design grid. MS Access Compound Queries Page 4

Simple Queries, Compound Queries It is a common mistake to get Or and And mixed up when typing a compound criteria for a single field. You may think to yourself, "I want all the Females in Veitongo and Ma ufanga," and then type: Veitongo And Ma ufanga in the Criteria row for the Town field. When you do this, you're asking Access to find rows where (Town = "Veitongo") And (Town = "Ma ufanga"). Since a field in a record can't have more than one value at a time (it can't contain both the values "Veitongo" and "Ma ufanga" in the same record), there won't be any records in the output. To look for all the rows for these two towns, you need to ask Access to search for (Town = "Veitongo") Or (Town = "Ma ufanga"). In other words, type Veitongo Or Ma ufanga in the Criteria row under the Town field. The criterias we have used so far have been simple because it has only required one particular solution. If you want to test for any of several values, enter the values in the Criteria row, separated by the word Or. For example, specifying Veitongo Or Ma ufanga searches for records for Veitongo or Ma ufanga. You can also test for any of several values by entering each value in a separate Criteria or Or row for the field you want to test. For example, you can enter OR in the Criteria row, Veitongo in the next row (the first Or row), and so on but you have to be careful if you're also specifying criteria in other fields, as explained in the side-box. AND vs. OR When you enter criteria for several fields, all of the tests in a single Criteria row or Or row must be true for a record to be displayed. That is, Access performs a logical AND operation between multiple criteria in the same row. So if you enter Veitongo in the Criteria row for [Town] and <100 in the Criteria row for Total Pay, the record must be for the Town of Veitongo and must have a pay of greater than 100 in order to be selected. If you enter Veitongo Or Ma ufanga in the Criteria row for [Town] and <=80 And >=50 in the Criteria row for [Total Pay], the record must be for the Town of Veitongo or Ma ufanga, and the Total Pay must be between 50 and 80 inclusive. Working the above samples out 1 Select the qryveitongo Pays and Edit Copy 2 Select Edit Paste this makes a copy of the original query for us to work with. In the Paste As dialog box type in the query name as Compound Quest 3 Open the query Compound Quest by double-clicking on it. 4 Go to design view by either using the View Design menu or by clicking on the Design icon Example 1 So if you enter Veitongo in the Criteria row for [Town] and <100 in the Criteria row for Total Pay, the record must be for the Town of Veitongo and must have a pay of greater than 100 in order to be selected. 1 In the Criteria row for Town enter Veitongo 2 On the same row, under the Total Pay column enter <100 3 Check the results in the Datasheet view, the listed people should all be from Veitongo and have a pay greater than 100. Example 2 If you enter Veitongo Or Ma ufanga in the Criteria row for [Town] and <=80 And >=50 in the MS Access Compound Queries Page 5

Criteria row for [Total Pay], the record must be for the Town of Veitongo or Ma ufanga, and the Total Pay must be between 50 and 80 inclusive. 1 GotoDesignView 2 In the Criteria row for Town type Veitongo Or Ma ufanga 3 On the same row and under the Total Pay column, type <=80 And >= 50 4 Check the results in the Datasheet view, the listed people should be either from Veitongo or Ma ufanga and have a pay between 50 and 80 inclusive. Example 3 When you do this, you're asking Access to find rows where (Town = "Veitongo") And (Town = "Ma ufanga"). Since a field in a record can't have more than one value at a time (it can't contain both the values "Veitongo" and "Ma ufanga" in the same record), there won't be any records in the output. To look for all the rows for these two towns, you need to ask Access to search for (Town = "Veitongo") Or (Town = "Ma ufanga"). In other words, type Veitongo Or Ma ufanga in the Criteria row under the Town field. 1 GotoDesignView 2 In the Criteria row for Town type Veitongo And Ma ufanga 3 On the same row and under the Total Pay column, type <=80 And >= 50 4 Check the results in the Datasheet view. Is anyone living in Veitongo and Ma ufanga. SOURCESOURCES AND REFERENCES: Bowden, Greg Guided Database Activities Using Microsoft Access (Cambridge, MS Access Compound Queries Page 6

Cambridge University Press, 1998) Microsoft Press, Running Microsoft Access 97 (Redmond, Microsoft Press, 1998) http://www.tongatapu.net.to/compstud/ - Computer Studies Course Notes http://www.tongatapu.net.to - Tonga on the 'NET http://www.tongatapu.net.to Salote College. is available on all networked computers at Queen 1999 No-Moa Publishers MS Access Compound Queries Page 7