SELECT Statements 2 Tables

Joins

So far we have only been manipulating one table at a time but if we want to show the Instructor Name and the Course Titles and Dates that they teach if we look at the two tables below we need fields from both tables.

To do this so far we could use: SELECT Instructor.Name, Course.Title, Course.Date FROM Instructor,Course

What is happening?

At the minute we are seeing 20 records instead of 5. We are seeing every Instructor is reaching every course. It can be represented using the diagram to the right:

To overcome this we will use an equi join, this is when two matching columns from related tables are selected (joined) using the foreign key.

What is being selected?

When we perform this type of JOIN we are selecting records that have matching values in BOTH tables.

SQL Statement Example

SQL Tutorial - SELECT on more than 1 table

3 SQL SELECT JOINS.mp4

This covers how to use a SELECT statement when using more than one table