1. Home
  2. Computing & Technology
  3. PHP / MySQL
photo of Angela Bradley
Angela's PHP / MySQL Blog

By Angela Bradley, About.com Guide to PHP / MySQL

Combining Tables with SQL

Monday May 1, 2006
Often data contained within two different tables of your MySQL database can share a common field that can be used to 'Join' the data. When using SELECT, you can name more than one table in FROM if you use a comma [,]. You can then join these tables together using the common field.

When selecting data from more than one table, you need to phrase it as tablename.fieldname. For example:

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

Here we use patients.name to describe the name field on the patients table, and meds.name to describe the name field on the meds table.
Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

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

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

All rights reserved.