SQL Server Left Join

Summary: in this tutorial, you will learn about the SQL Server LEFT JOIN clause and how to query data from multiple tables.

Introduction to SQL Server LEFT JOIN clause #

The LEFT JOIN is a clause of the SELECT statement. The LEFT JOIN clause allows you to query data from multiple tables.

The LEFT JOIN returns all rows from the left table and the matching rows from the right table. If no matching rows are found in the right table, NULL are used.

The following illustrates how to join two tables T1 and T2 using the LEFT JOIN clause:

SELECT
    select_list
FROM
    T1
LEFT JOIN T2 ON
    join_predicate;
Code language: SQL (Structured Query Language) (sql)

In this syntax, T1 and T2 are the left and right tables, respectively.

For each row from the T1 table, the query compares it with all the rows from the T2 table. If a pair of rows causes the join predicate to evaluate to TRUE, the column values from these rows will be combined to form a new row which is then included in the result set.

If a row from the left table (T1) does not have any matching row from the T2 table, the query combines column values of the row from the left table with NULL for each column value from the right table.

In short, the LEFT JOIN clause returns all rows from the left table (T1) and matching rows or NULL values from the right table (T2).

The following illustrates the LEFT JOIN of two tables T1(1, 2, 3) and T2(A, B, C). The LEFT JOIN will match rows from the T1 table with the rows from the T2 table using patterns: