How To

How to Join Two Tables in a Relational Database

By Mike, eHow Member Rating
Database
Database
Rate: (4 Ratings)

The power of a relational database such as Oracle, SQL Server, MySQL and Access is the ability to relate two or more tables based on common fields. Here is how you can join two tables on a common field. I am using MS Access's Northwind database to write the SQL statement.

Difficulty: Easy
Instructions

Things You'll Need:

  • A relational database
  1. Step 1
    Database
    Database

    Open your relational database. For my example I am using Microsoft's Northwind database, which is the database that comes with Microsoft.

  2. Step 2
    Tables
    Tables

    I am going to use the orders table and the orders detail table and I will relate the two tables based on the Order ID field. Each order has a unique index called the order id. This order id is saved in the order details table since you can have multiple items purchased on the same order.

  3. Step 3
    SQL statement
    SQL statement

    I selected a couple of fields from both tables so you can see how the data is returned. I then join the two tables on the order if field. So my SQL statement looks like this:

    "SELECT [Order Details].OrderID, [Order Details].ProductID, Orders.OrderDate, Orders.ShippedDate, [Order Details].UnitPrice
    FROM Orders, [order details] where Orders.OrderID = [Order Details].OrderID;"

    Anything you see enclosed with [] means that the field or table name is more than one word using a space to separate the words.

  4. Step 4
    Final results
    Final results

    Now run your sql statement. You will see the fields selected displayed and the two tables joined.

Tips & Warnings
  • You can also use the INNER JOIN statement as well to do the same thing.
Resources

Comments  

Flag This Comment

on 10/14/2008 helpful article... thanks!

luv2blog said

Flag This Comment

on 10/12/2008 Thanks for the info.

Post a Comment

Post a Comment

Have you done this? Click here to let us know.

I Did This

Related Ads

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.

eHow Computers
eHow_eHow Technology and Electronics