LEFT JOIN

A LEFT JOIN is used in SQL to combine rows from two tables. It returns all records from the left table and the matched records from the right table. If there is no match, the result will still include the left table’s row, but the right table’s columns will contain NULL.

Syntax

SELECT columns
FROM left_table
LEFT JOIN right_table
ON left_table.common_column = right_table.common_column;

Key Points

  • The left table is the table listed before LEFT JOIN.
  • The right table is the table listed after LEFT JOIN.
  • Rows from the left table are always included in the result.
  • If no matching row exists in the right table, NULL is displayed for those columns.
  • LEFT JOIN is useful when you want to include all data from one table, even if it doesn’t have a related record in another table.

Example

Suppose we have two tables:

Students
ID | Name
1 | Alice
2 | Bob
3 | Carol

Grades
StudentID | Grade
1 | A
3 | B

Query:

SELECT Students.ID, Students.Name, Grades.Grade
FROM Students
LEFT JOIN Grades
ON Students.ID = Grades.StudentID;

Result:

ID | Name | Grade
1 | Alice | A
2 | Bob | NULL
3 | Carol | B

Explanation: Bob has no grade, so the result shows NULL in the Grade column.

When to Use LEFT JOIN

  • When you want all records from the main table even if related records are missing in another table.
  • To detect missing relationships between tables.
  • To combine optional information with mandatory data.
Home » SQL Foundations Program (SQL-101) > Basic Joins > LEFT JOIN