The LEFT JOIN clause allows us to match data from two or more database tables. Same as INNER JOIN, this clause as well should be applied after the clause FROM. Following syntax shows are how to use the LEFT JOIN clause:

Syntax

SELECT Table1.col1, Table1.col2,... Table2.col1, Table2.col2 

FROM Table1 LEFT JOIN Table2 ON Table1.col1 = Table2.col1...;

If the row from the left table of the condition (from example above: Table1.col1 = Table2.col1) does not match the right one, the result values from the left table's row (Table1), and NULL which then replaces the values from the right table. Therefore the MySQL lets you execute the join even if the rows don't match.

The LEFT JOIN clause is very useful when we want to find the rows in the left table that do not match the rows in the other one. To find the unmatched rows we should use the WHERE clause in a SELECT statement to select those rows whose columns values (in the right table) contain the NULL values.

Here is an example:

SELECT c.customer, c.customerAddress, order, o.status 

FROM customers c 

LEFT JOIN orders o ON c.customer = o.customer 

WHERE order IS NULL;

RIGHT JOIN clause

We can replace the LEFT JOIN clause with the RIGHT JOIN to achieve the joining of two or more tables with the right one as priority. Therefore the syntax is the same; except that the result set will be prioritize by the right table.