Joins are used to select matching values from two tables.
Syntax:
SELECT a.columnX, b.columnY
FROM TableA a
JOIN TableB b
ON a.columnZ = b.columnT
columnX
and columnZ
are any columns from
TableA
.
columnY
and columnT
are any columns from
TableB
.
ON
clause compares columns of different data types,
an implicit conversion will occur, or an error will be thrown if strict
mode is enabled in some database management systems.
ON a.Age = b.FullName
(Both
Age
and FullName
are converted to strings for
comparison).
There are four types of joins:
Note: A self join is a type of join where a table is joined with itself using the same syntax as for other joins (e.g., Inner Join, Left Join, Right Join, Full Join).
INNER JOIN