
LEFT JOINS
LEFT JOIN OR LEFT OUTER JOIN
In SQL, the LEFT JOIN (also called LEFT OUTER JOIN) retrieves all records from the left table and only the matching records from the right table. If no match is found, NULL values are returned for the right table columns.
SYNTAX
SELECT column_name(s)
FROM tableA
LEFT JOIN tableB ON tableA.column_name = tableB.column_name;
Examples of SQL LEFT JOIN
First, we will create a demo SQL database and tables. Consider two tables: Emp (employees) and department (departments). The Emp table contains employee details, while the department table holds department details.
Employee Table:

Department Table:

Example
To perform left-join on Employee and Department Tables we will use the following SQL query:
Query:
SELECT Emp.EmpID, Emp.Name, department.
department_name, department.department_head,
department.location
FROM Emp
LEFT JOIN department ON Emp.department_id = department.department_id;
Output:

- All employees (left table) are included.
- Since each employee is assigned a department, we see matching details from the right table.
- If an employee had no department assigned, the department columns would show NULL
Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments