SQL Joins   «Prev  Next»

Lesson 5 INNER and OUTER joins
Objective Understand what INNER and OUTER joins are.

SQL INNER JOIN statement

The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.

SQL INNER JOIN Syntax:

SELECT column_name(s) 
FROM table1 INNER JOIN table2 
ON table1.column_name=table2.column_name;

or
SELECT column_name(s) 
FROM table1 JOIN table2 
ON table1.column_name=table2.column_name;

Note: An INNER JOIN is the same as JOIN.
Venn Diagram for Inner Join

Build SQL Statements based on table information

Early on in this course, we investigated what it meant to have a normalized database and its associated tables. Although normalization is not an SQL statement, it is something that you use when you query a table with SQL. You need to understand the mechanics as they relate to how to use the information in the table and how to build your SQL statements.
Joins, specifically the INNER and OUTER join approaches are much the same thing. An INNER join is the most common type of join. It simply returns the rows that match the WHERE clause, and entries that do not have matches will not be included in the results. An OUTER join will show you all of the rows from one or both of the tables, regardless of whether those rows match rows in the other table.
In the next lesson, we will look at three types of OUTER joins:
  1. LEFT,
  2. RIGHT, and
  3. FULL joins.