Learn SQL - Multiple Tables Cheatsheet - Codecademy
Learn SQL - Multiple Tables Cheatsheet - Codecademy
Multiple Tables
Outer Join
An outer join will combine rows from different tables even
if the join condition is not met. In a LEFT JOIN , every row SELECT column_name(s)
in the left table is returned in the result set, and if the join FROM table1
condition is not met, then NULL values are used to fill in
ON table1.column_name
= table2.column_name;
WITH Clause
The WITH clause stores the result of a query in a
temporary table ( temporary_movies ) using an alias. WITH temporary_movies AS (
FROM movies
SELECT *
FROM temporary_movies
UNION Clause
The UNION clause is used to combine results that appear
from multiple SELECT statements and filter duplicates. SELECT name
name UNION
and a last_names table with a column name containing
SELECT name
rows of data “James”, “Hermione” and “Cassidy”, the
FROM last_names
result of this query would contain three name s:
Inner Join
The JOIN clause allows for the return of results from
more than one table by joining them together with other SELECT *
JOIN authors
only return results matching the condition specified by
Primary Key
A primary key column in a SQL table is used to uniquely
identify each record in that table. A primary key cannot
be NULL . In the example, customer_id is the primary key.
The same value cannot re-occur in a primary key column.
Primary keys are often used in JOIN operations.