Skip to Content
Go Realm v1 is released 🎉
DatabaseJoin Types

🔗 Join Types (With Examples)

  • What is an INNER JOIN?
An INNER JOIN returns only the rows that have matching values in both tables. If there is no match, the row is excluded from the result.
  • What is a LEFT JOIN?
A LEFT JOIN returns all rows from the left table, and the matched rows from the right table. If there is no match, NULLs are returned for columns from the right table.
  • What is a RIGHT JOIN?
A RIGHT JOIN returns all rows from the right table, and the matched rows from the left table. If there is no match, NULLs are returned for columns from the left table.
  • What is a FULL OUTER JOIN?
A FULL OUTER JOIN returns all rows when there is a match in either the left or right table. Rows with no match in one of the tables will have NULLs for the missing side.
  • When should each type of join be used?
- Use **INNER JOIN** when you only want records with matches in both tables. - Use **LEFT JOIN** when you need all records from the left table, even if there's no match. - Use **RIGHT JOIN** when you need all records from the right table, even if there's no match. - Use **FULL OUTER JOIN** when you want all records from both tables, matched where possible.
  • Provide examples for each join type:

Assume two tables: Employees

idnamedept_id
1Alice10
2Bob20
3CharlieNULL

Departments

iddept_name
10HR
20Engineering
30Marketing

✅ INNER JOIN Example:

SELECT Employees.name, Departments.dept_name FROM Employees INNER JOIN Departments ON Employees.dept_id = Departments.id;

Result:

namedept_name
AliceHR
BobEngineering

✅ LEFT JOIN Example:

SELECT Employees.name, Departments.dept_name FROM Employees LEFT JOIN Departments ON Employees.dept_id = Departments.id;

Result:

namedept_name
AliceHR
BobEngineering
CharlieNULL

✅ RIGHT JOIN Example:

SELECT Employees.name, Departments.dept_name FROM Employees RIGHT JOIN Departments ON Employees.dept_id = Departments.id;

Result:

namedept_name
AliceHR
BobEngineering
NULLMarketing

✅ FULL OUTER JOIN Example:

SELECT Employees.name, Departments.dept_name FROM Employees FULL OUTER JOIN Departments ON Employees.dept_id = Departments.id;

Result:

namedept_name
AliceHR
BobEngineering
CharlieNULL
NULLMarketing