Skip to main content

Linking Tables

To select data from two or more tables we need to know the linking columns. Although not necessary, it is good practice to use the same name for the linking columns when creating tables.

The link is actually between the primary key in one table (do you remember what a primary key is?) and the same column in another table. For your information, the column in the other table is called a foreign key.

SELECT column, column, ....

FROM tablename

WHERE tablename1.column = tablename2.column;

The link is established by use of the WHERE clause of the SQL SELECT command.

If a primary key in one table comprises more than one column then all those columns must also be in the linking table.

SELECT column, column, ....

FROM tablename

WHERE tablename1.column1 = tablename2.column1

AND tablename1.column2 = tablename2.column2;

Next: Linking Tables Example