Lecture 4 Flashcards
What are SQL joins? and what are the 4 we must know?
A join clause is used to combine rows from two or more tables, based on a related column between them.
Inner, Outer, Left and Right
Simple/INNER JOIN
Only the things that match on the left and the right.
SELECT *
FROM table1
INNER JOIN Table2
ON table1.KEY = Table2.KEY
Left JOIN
Everything on the left, plus anything on the right that matches.
SELECT *
FROM table1
LEFT JOIN Table2
ON table1.KEY = Table2.KEY
Right JOIN
Everything on the right, plus anything on the left that matches.
SELECT *
FROM table1
RIGHT JOIN Table2
ON table1.KEY = Table2.KEY
Outer JOIN
Everything on the right, plus everything on the left.
SELECT *
FROM table1
OUTER JOIN Table2
ON table1.KEY = Table2.KEY
AS
AS is an aliase to tables or columns to make queries shorter or more readable.
USING
We can use USING if the names of columns in both join tables are equal.