Left Join in SQL


Left Join in SQL

The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in the right table. This means that if the ON clause matches 0 (zero) records in the right table; the join will still return a row in the result, but with NULL in each column from the right table.

Below is the student table which has a row in which the department column is NULL.

The department table will be as follows

Now if we apply the LEFT JOIN as follows

					SELECT STUDENT.FirstName, STUDENT.LastName, DEPARTMENT.DepartmentName
ON STUDENT.DepartmentId = DEPARTMENT.DepartmentId

We will get the below result where we will get all the matched rows as well as unmatched rows from the left table and all the matched rows from the right table and NULL value for the unmatched rows.

Please comment and share if you like this post and tell us about how we can enhance our posts. Thanks.