1. Computing & Technology

Discuss in my forum

Using SQL Joins

By , About.com Guide

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.

©2012 About.com. All rights reserved.

A part of The New York Times Company.