Pages

Wednesday, October 23, 2013

How to Access Data in Two Different Tables

How to Access Data in Two Different Tables

One of the most powerful functions in a database is the ability to retrieve data from two different tables. Let's say you have one table that has the name of every salesperson in your company and another table with sales data. To see what a salesperson has sold, you can either look at each table separately or you can join the tables using a query so you have all of the data in one easy-to-read display.

Instructions

    1

    Open up an Access database and create a new query by clicking the "Create" tab. Move the mouse pointer to the right side of the "Create" ribbon and click "Query Design" to make the "Show Table" form appear.

    2

    Click on the table names in the "Show Table" form to highlight the tables you want to include in your query. Click the "Add" button to add the tables to the query and close the form. In the query window, the tables you've selected appear in the top half of the window and the bottom half contains a grid for fields from the tables. In this guide, let's imagine you have two tables: Employees and Sales. In the Employees table, the fields are EmployeeID, LastName and FirstName. In the Sales table, the fields are EmployeeID, Product, SalesDate and Amount.

    3

    Click and hold the mouse button on the EmployeeID field in the Employees table and drag over to the EmployeeID field in the Sales table and release the mouse button. When you do this, a connecting line will appear between the two fields.

    4

    Add fields to the grid in the query window by double-clicking names in the tables in the upper half of the window. In this example, if you want to see the name of the salesperson and what he has sold, select FirstName, LastName from the Employees table and select Product, SalesDate and Amount from the Sales table.

    5

    Move the mouse pointer to the upper, left corner of the Access window and click the "View" button to see your results.

0 comments:

Post a Comment