INNER JOIN:
is used when retrieving data from multiple
tables and will return only matching data.
LEFT OUTER JOIN:
is used when retrieving data from
multiple tables and will return
left table and any matching right table records.
RIGHT OUTER JOIN:
is used when retrieving data from
multiple tables and will return right
table and any matching left table records
FULL OUTER JOIN:
is used when retrieving data from
multiple tables and will return both
table records, matching and non-matching.
In SQL, a join is used to compare and combine — literally join — and
return specific rows of data from two or more tables in a database.
An inner join finds and returns matching data from tables,
while an outer join finds and returns matching data and some dissimilar
data from tables
INNER JOIN :
The inner join will keep only the information from the two joined tables
that is related.
OUTER JOIN:
There are three types of outer joins:
Left Outer Join (or Left Join)
Right Outer Join (or Right Join)
Full Outer Join (or Full Join)
-- Rows with ID existing in both a and b
-- JOIN is equivalent to INNER JOIN
SELECT a.ID, a.NAME, b.VALUE1 FROM table1 a
JOIN table2 b ON a.ID = b.ID
WHERE a.ID >= 1000;
-- ⇓ Test it ⇓ (Fiddle source link)
INNER JOIN:
is used when retrieving data from multiple
tables and will return only matching data.
FULL OUTER JOIN:
is used when retrieving data from
multiple tables and will return both
table records, matching and non-matching.