1. Home
  2. Computing & Technology
  3. PHP / MySQL

Using SQL Joins

By Angela Bradley, About.com

2 of 4

Simple Joining

Now let's say we wanted to list our patients, their current medication, and it's dosage. This information is held on separate tables, so we would need to run a "join" to get the desired result.

SELECT patients.name, meds.name, meds.dose FROM patients, meds WHERE (patients.med_id = meds.med_id)

We now have the person's name displayed with their medicine and dosage. You will notice that since we are now working with more than one table, we refer to the data fields as table.field. Also you will see that the WHERE clause pulls information from the second table ONLY if relevant to the first table. Try running this again without the WHERE clause. You will instead see all possible combinations.

Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Learn MySQL
  5. SQL Join - SQL Join Tutorial - SQL Join Type

©2009 About.com, a part of The New York Times Company.

All rights reserved.