Introduction to MySQL Commands and Tips
This note provides a comprehensive overview of commonly used MySQL Joins and Unions commands.
Inner Joins
Returns only the rows that have matching values in both tables.
|
|
LEFT JOIN (or LEFT OUTER JOIN)
Returns all rows from the left table and matched rows from the right table. If no match is found, NULL values are returned for columns from the right table.
|
|
RIGHT JOIN (or RIGHT OUTER JOIN
Returns all rows from the right table and matched rows from the left table. If no match is found, NULL values are returned for columns from the left table.
|
|
FULL JOIN (or FULL OUTER JOIN)
Returns all rows when there is a match in either left or right table. If there is no match, NULL values are returned for columns of the table that lacks a match.
|
|
CROSS JOIN
Returns the Cartesian product of the two tables, i.e., all possible combinations of rows from the tables.
|
|
SELF JOIN
A join where a table is joined with itself. Typically used with table aliases.
|
|
Union
Unions are used to combine the results of two or more SELECT queries into a single result set. The queries combined with a union must have the same number of columns and compatible data types. UNION: Combines the result sets of two or more SELECT queries and removes duplicate rows.
|
|
UNION ALL: Combines the result sets of two or more SELECT queries and includes all rows, including duplicates.
|
|