Return all rows from the left table and matching rows from the right table or null if no matching rows are found in the right table.

Here’s a LEFT JOIN rewrite based on your query, followed by an explanation:
SELECT
Table1.column1,
Table2.column2
FROM
Table1
LEFT JOIN Table2
ON Table1.common_column = Table2.common_column
WHERE
Table1.some_column = 'some_value'
ORDER BY
Table1.column1 DESC;
Explanation of the LEFT JOIN:
- FROM Table1: This specifies that
Table1is the main or "left" table from which we will retrieve data. - LEFT JOIN Table2 ON Table1.common_column = Table2.common_column: This part joins
Table1withTable2using thecommon_column. TheLEFT JOINensures: - All rows from
Table1are included in the result set. - If a row in
Table1doesn’t have a matching row inTable2, theTable2columns in that row are filled withNULLvalues. - If a match is found, data from both tables is combined into a single row.
- WHERE Table1.some_column = 'some_value': This condition filters the rows from
Table1based on a specific value inTable1.some_column. Only rows fromTable1that meet this condition will appear in the results. - ORDER BY Table1.column1 DESC: This sorts the final results in descending order by
Table1.column1.
Visual Summary of LEFT JOIN:
Imagine two tables (Table1 on the left and Table2 on the right). The LEFT JOIN:
- Includes all rows from the left table (
Table1). - Combines data from
Table2if there’s a match. - Fills
Table2columns withNULLif there’s no match for aTable1row.
In contrast, an INNER JOIN would only include rows where there’s a match between Table1 and Table2, excluding rows in Table1 without a match.
This behavior makes LEFT JOINs helpful when you need complete data from one table (like Table1) and any matching data from another (Table2).
MySQL LEFT JOIN clause examples
Let’s take some examples of using the LEFT JOIN clause.

Question
Given two tables, customers and orders, in the sample database, write a query to retrieve all customers along with any orders they have placed.
- The
customerstable includes columnscustomerNumberandcustomerName. - The
orderstable includes columnsorderNumber,status, andcustomerNumber. - Each customer may have zero or more orders, but each order belongs to only one customer.
Task
Write a query to return:
customerNumberandcustomerNamefrom thecustomerstable.orderNumberandstatusfrom theorderstable.
Requirements
- Use a
LEFT JOINto include all customers, whether or not they have orders. - Simplify the query by using table aliases for readability.
SELECT
c.customerNumber,
customerName,
orderNumber,
status
FROM
customers AS c
LEFT JOIN orders AS o
ON c.customerNumber = o.customerNumber;Using MySQL LEFT JOIN clause to find unmatched rows
The LEFT JOIN clause is very useful when you need to identify rows in a table that doesn’t have a matching row from another table.
Question 7
The LEFT JOIN clause is particularly useful for identifying rows in one table that do not have matching rows in another table. This task demonstrates how to use LEFT JOIN to find customers who have not placed any orders.
- The
customerstable includes columnscustomerNumberandcustomerName. - The
orderstable includes columnsorderNumber,status, andcustomerNumber.
Task
Write a query to return:
customerNumberandcustomerNamefrom thecustomerstable.orderNumberandstatusfrom theorderstable.
Requirements
- Use a
LEFT JOINto include all customers, even if they do not have any associated orders. - Add a condition to filter out customers with orders, showing only those who have not placed any orders.
SELECT
c.customerNumber,
c.customerName,
o.orderNumber,
o.status
FROM
customers c
LEFT JOIN orders o
ON c.customerNumber = o.customerNumber
WHERE
orderNumber IS NULL;Using MySQL LEFT JOIN to join three tables
See the following three tables employees, customers, and payments:

This task demonstrates how to use multiple LEFT JOIN clauses to join three tables: employees, customers, and payments.
- The
employeestable includes columnsemployeeNumber,lastName, andfirstName. - The
customerstable includes columnscustomerNumber,customerName, andsalesRepEmployeeNumber(which referencesemployeeNumber). - The
paymentstable includes columnscustomerNumber,checkNumber, andamount.
Task
Write a query to return:
lastNameandfirstNamefrom theemployeestable.customerNamefrom thecustomerstable.checkNumberandamountfrom thepaymentstable.
Requirements
- Use two
LEFT JOINclauses to join theemployees,customers, andpaymentstables. - Order the results by
customerNameandcheckNumberfor clarity.
SELECT
lastName,
firstName,
customerName,
checkNumber,
amount
FROM
employees
LEFT JOIN customers ON
employeeNumber = salesRepEmployeeNumber
LEFT JOIN payments ON
payments.customerNumber = customers.customerNumber
ORDER BY
customerName,
checkNumber;Condition in WHERE clause vs. ON clause
The following example uses the LEFT JOIN clause to query data from the orders and orderDetails tables:
SELECT
o.orderNumber,
customerNumber,
productCode
FROM
orders o
LEFT JOIN orderDetails
USING (orderNumber)
WHERE
orderNumber = 10123;The query returns the order and its line items of the order number 10123.

However, if you move the condition from the WHERE clause to the ON clause:
SELECT
o.orderNumber,
customerNumber,
productCode
FROM
orders o
LEFT JOIN orderDetails d
ON o.orderNumber = d.orderNumber AND
o.orderNumber = 10123;It will have a different meaning.
In this case, the query returns all orders; However, only the order 10123 will have associated line items as shown in the query result:

Notice that for INNER JOIN clause, the condition in the ON clause is equivalent to the condition in the WHERE clause.
In this tutorial, you have learned how to use the MySQL LEFT JOIN clause to join data from two or more tables.