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.
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
