1. Computing

Discuss in my forum

Angela Bradley

Combining Tables with SQL

By , About.com GuideMay 1, 2006

Follow me on:

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>
Top Related Searches may 1 2006

©2013 About.com. All rights reserved.