SQL LEFT JOIN

LEFT JOIN combines the values of the first table to the values of the second table. Always return the rows from the first table, even if they meet the condition.

SELECT * FROM table1 LEFT JOIN table2 WHERE table1.column1 = table2.column1

LEFT JOIN Example

people table with primary key "per"

pernamesurnamenicknamedep
1HARRYCLARKWHITE1
2HARRYSMITHJOHNSON2
3JOHNBROWNANDERSON4

table "departments" with primary key "dep"

depdepartamento
1ADMINISTRATION
2COMPUTER
3BUSINESS

SELECT name, surname, department FROM people LEFT JOIN departments WHERE people.dep = departamentos.dep
namesurnamedepartamento
HARRYCLARKADMINISTRATION
HARRYSMITHCOMPUTER
JOHNBROWN

Although the department '4' for JOHN BROWN does not exist in the department table, return the row with the column 'department' blank.