INNER JOINs

This YouTube video was created by Steve Griffith.

The INNER JOIN selects records that have matching values in both tables. This kind of relationship can be represented by the follow venn diagram.

Venn Diagram with the inner part colored representing an INNER JOIN

The INNER JOIN follows the FROM clause and first table name. This in turn is followed by the name of the second table the ON keyword and the join condition.

NOTE

When working with more than one table, it is sometimes necessary to specify the table along with the column using a dot syntax. The table name or alias can be used.

Example: table.column

# Retrieving the title, director, year, and genre title for each movie
SELECT m.movie_title, m.director, m.year, g.genre_title 
FROM movies as m
INNER JOIN genres as g
ON m.genre_id = g.genre_id

NOTE

The backticks (`) around table names and column names is only required if the names have a space. While it is good practice to include backticks, it becomes cumbersome when using the dot syntax.

# The above example using backticks
SELECT `m`.`movie_title`, `m`.`director`, `m`.`year`, `g`.`genre_title` 
FROM `movies` as `m`
INNER JOIN `genres` as `g`
ON `m`.`genre_id` = `g`.`genre_id`