What is the difference between LEFT JOIN and INNER JOIN?
sobes.tech AI
Answer from AI
INNER JOIN returns only those rows for which there are matches in both joined tables.
LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table and the matching rows from the right table. If there are no matches in the right table, NULL values are returned for the columns of the right table.
Example:
Suppose there are two tables: Employees (id, name) and Departments (id, name, manager_id).
INNER JOIN Employees AND Departments ON Employees.id = Departments.manager_id
Returns only those employees who are managers of departments.
LEFT JOIN Employees AND Departments ON Employees.id = Departments.manager_id
Returns all employees. For those who are managers of departments, department data will also be included. For employees who are not managers, the columns from the Departments table will contain NULL.