programming4us
 
Office
 

Microsoft Access 2010 : Enhancing the Queries That You Build - Building Queries Based on Multiple Tables - Pitfalls of Multitable Queries

10/16/2014 9:57:15 PM

If you have properly normalized your table data, you probably want to bring the data from your tables back together by using queries. Fortunately, you can do this quite easily by using Access queries.

The query in Figure 1 joins the Customers, Orders, and Order Details tables, pulling fields from each. Notice in the figure that I have selected the ID and Company fields from the Customers table, the Order ID and Order Date fields from the Orders table, and the Unit Price and Quantity fields from the Order Details table. After you run this query, you should see the results shown in Figure 2. Notice that you get a record in the query’s result for every record in the Order Details table. In other words, there are 68 records in the Order Details table, and that’s how many records appear in the query output. By creating a multitable query, you can look at data from related tables, along with the data from the Order Details table.

Figure 1. A query joining the Customers, Orders, and Order Details tables.

Figure 2. The results of querying multiple tables.

By setting up relationships between tables in a database, Access knows how to properly join them in the queries that you build.


To remove a table from a query, you click anywhere on the table in the top half of the query design grid and then press the Delete key. You can add tables to the query at any time by clicking the Show Table button on the toolbar. If you prefer, you can select the Database window and then click and drag tables directly from the Database window to the top half of the query design grid.


Pitfalls of Multitable Queries

You should be aware of some pitfalls of multitable queries: They involve updating and which records you see in the query output.

It’s important to remember that you cannot update certain fields in a multitable query. You cannot update the join fields on the “one” side of a one-to-many relationship (unless you’ve activated the Cascade Update Referential Integrity feature). You also can’t update the join field on the “many” side of a relationship after you’ve updated data on the “one” side. More importantly, which fields you can update, and the consequences of updating them, might surprise you. If you update the fields on the “one” side of a one-to-many relationship, you must be aware of that change’s impact. You’re actually updating that record in the original table on the “one” side of the relationship, and several records on the “many” side of the relationship may be affected.

For example, Figure 3 shows the result of a query based on the Customers, Orders, and Order Details tables. I have changed Company D to InfoTech Services Group on a specific record of the query output. You might expect this change to affect only that specific order detail item. However, pressing the down-arrow key to move off the record shows that all records associated with Company D are changed (see Figure 4). This happens because all the orders for Company D were actually getting their information from one record in the Customers table—the record for ID 12—and that is the record I modified while viewing the query result.

Figure 3. Changing a record on the “one” side of a one-to-many relationship.

Figure 4. The result of changing a record on the “one” side of a one-to-many relationship.

The second pitfall of multitable queries has to do with figuring out which records result from a multitable query. So far, you have learned how to build only inner joins. You need to understand that the query output contains only customers who have orders and orders that have order details. This means that not all the customers or orders might be listed.

 
Others
 
- Microsoft Access 2010 : Relating the Information in Your Database - Establishing Referential Integrity
- Microsoft Project 2010 : Project on the Internet (part 5) - Integrating Project and Outlook - Routing a Project file to several recipients
- Microsoft Project 2010 : Project on the Internet (part 4) - Integrating Project and Outlook - Sending Project Information to Others
- Microsoft Project 2010 : Project on the Internet (part 3) - Integrating Project and Outlook - Importing Tasks from Outlook, Copying Tasks from an Email
- Microsoft Project 2010 : Project on the Internet (part 2) - Hyperlinking to Information - Creating a Hyperlink to a Location in the Project File
- Microsoft Project 2010 : Project on the Internet (part 1) - Hyperlinking to Information - Creating a Hyperlink to a File or Web Page
- Microsoft Word 2010 : Creating an Index (part 2) - Adding an Index to a Document - Generating an Index
- Microsoft Word 2010 : Creating an Index (part 1) - Adding an Index to a Document - Marking an Index Entry
- Microsoft Word 2010 : Creating a Table of Contents (part 2) - Adding a TOC to a Document - Inserting a Customized Table of Contents
- Microsoft Word 2010 : Creating a Table of Contents (part 1) - Adding a TOC to a Document - Inserting an Automatic Table of Contents
 
 
REVIEW
 
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- Sigma 24mm f/1.4 DG HSM Art

- Canon EF11-24mm f/4L USM

- Creative Sound Blaster Roar 2

- Alienware 17 - Dell's Alienware laptops

- Smartwatch : Wellograph

- Xiaomi Redmi 2
 
VIDEO TUTORIAL
 
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
 
Top 10
 
- How To Install Android Market & Google Apps On Kindle Fire
- How To Make Ubuntu Look Like Windows 7
- How To Add A New Account in MS Outlook 2013
- Get Android & Mac OS X Style Gadgets For Windows 7 & Windows 8 With XWidget
- How To Activate Microsoft Office 2013
- How To Install Actual Facebook App On Kindle Fire
- How To Create, View And Edit Microsoft Office Files On Kindle Fire
- Download Attractive Business PowerPoint Templates For Free At SlideHunter
- How To Use And Enable Hibernate & Sleep Mode In Windows 8
- How To Get Microsoft Office 2013 Trial Product Key From Microsoft