« Creating Calculated Fields in OpenOffice Base | Main | Kathy Sierra Is a Good Friend Who Wants to Help People Kick Butt....Nooses Are Not an Appropriate Reaction (For Her or Anyone Else) »

March 28, 2007

Sample Project for Joining Tables, Regarding Primary Keys

If you don't spend every day hip deep in databases, you might not always be clear on the whole primary key thing, and how to join them.

I want to clarify that this will work.

Let's say you've got two tables.

One is a table with city residents' IDs and names, street numbers, street names, etc.

The other is a table with street names and the days on which garbage is collected.

G1_2

G2

You need to send people a letter telling them what day their garbage is collected on. Thus you need to link the two tables.

The primary key on the first table, the ID field, is different than the primary key on the second. The primary key on the second could be the street name since the street name is unique in that table.

1   Oak    Monday
2  Elm     Monday
3  Main  Tuesday

and so on.

To create the query, you don't need to link the primary keys. You can link the two tables simply by connecting the two Street Name fields when you create the query.

1. Open the database file containing the two tables.
2. Click the Queries icon at the left.
3. Click the option to create a query in design view.

G3

4. In the window that appears, select the first table name and click Add.

5. Select the second table name and click Add.

G4

6. Click in the second table, on the common field, in this case the StreetName field, and drag your mouse to the other table's StreetName field. (If this doesn't work, drag from the first table's field to the second table's field.)

G5small

7. Now create your query. Double-click the name of any field you want in the query. In this case it might be Name, Street Number, Street Name, and Garbage Day.

G6

Run the query by clicking the Run Query icon.

G7smallish

The results will appear.

G8

Save the query and close it.

G9

Now create your mail merge. You can create a new Text Document and choose View > Data Sources. Open the database containing the query and under Queries select the query you created

Drag the fields you want into the letter. You might want it like this.

G10




TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/551685/17164554

Listed below are links to weblogs that reference Sample Project for Joining Tables, Regarding Primary Keys:

Comments

It would be nice to have also an example with three tables. I.e. AddressesTable, LinkAddressesCategories, and Category table.

This way one could show how to resolve a many to many relationship.

AddressesTable, LinkAddressesCategories, and Category table. http://www.batterygoshop.co.uk/uniwill/255-3s4400-g1l1-battery.htm uniwill 255-3s4400-g1l1 battery ,

Post a comment