SQL RIGHT JOIN

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

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

EXAMPLE SQL RIGHT JOIN

pernamesurnamenicknamedep
1HARRYCLARKWHITE1
2HARRYSMITHJOHNSON2
3JOHNBROWNANDERSON4

table "departments" with primary key "dep"

depdepartamento
1ADMINISTRATION
2COMPUTER
3BUSINESS

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

Although there is no person in the department 'BUSINESS' (3), this row will appear with the other columns blank