Skip to content

SQL LEFT JOIN Clause

Syntax

The LEFT JOIN clause in SQL is used to combine rows from two tables. It returns all rows from the left table and matching rows from the right table; unmatched rows from the right table will show NULL.

-- Left join two tables on a common column
SELECT table1.column1, table2.column2
FROM table1
LEFT JOIN table2
ON table1.common_column = table2.common_column;

Example

-- Retrieve employees and their corresponding department names, including employees without a department
SELECT employees.name, departments.department_name
FROM employees
LEFT JOIN departments
ON employees.department_id = departments.id;
/* Output:
| name | department_name |
|------------|-----------------|
| John Doe | Sales |
| Jane Smith | Marketing |
| Alice Brown| HR |
| Bob White | NULL |
*/