Posts: 2,536
Location: Western Maryland
|
Fambi, the two tables must have a relationship -- a key on each that is shared. For example, I have a table MOVIES with movieid, title and directorid; and the director field is an int. I have a directors table that has a directorid, name, birth day, favorite color, etc. The directorid field on the directors table holds a unique number for each row that uniquely identifies it -- that's the primary key. The directorid field in the MOVIES table is a reference to the directorid field on the directors table. That is called a foreign key.
Now that the relationship is there, I can create a query which joins the two sets of data together. Let's say I wanted to find out the name and favorite color of the director of a movie called "FRANK." So the movie title lives in one table (movies) and the favorite color and name live in the other (directors).
Code:
SELECT d.birthDay, d.Name FROM directors d INNER JOIN movies m ON d.directorid=m.directorid WHERE m.title = 'FRANK'
This is a called a "join."
__________________
—Kyrnt
|