Skip to content
We areTOP 1%

What are the different types of joins in SQL?

EasyConceptSQL: Joins
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

A join combines rows from two tables using a condition, usually equality between a foreign key and a primary key. The join type decides what happens to rows that have no match.

  • INNER JOIN: only the rows that match in both tables.
  • LEFT (OUTER) JOIN: all rows of the left table; unmatched rows get NULL in the right table's columns. RIGHT JOIN is the mirror image.
  • FULL OUTER JOIN: all rows from both sides. MySQL does not support it; emulate it with a UNION of a left and a right join.
  • CROSS JOIN: every combination of rows (m × n rows). A self join joins a table with itself using two aliases.

Example:

students(id, name)     marks(student_id, score)
1 | Asha               1 | 90
2 | Ravi               3 | 75

Joining on id = student_id:

  • INNER JOIN: Asha | 90
  • LEFT JOIN: Asha | 90, Ravi | NULL
  • RIGHT JOIN: Asha | 90, NULL | 75
  • FULL OUTER JOIN: all three rows above
  • CROSS JOIN: 2 × 2 = 4 rows

More in SQL: Joins

SQL: Joins questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1What are the different types of joins in SQL?
EasyConcept
ConceptEasy Read the answer to What are the different types of joins in SQL?
2What is the difference between UNION and UNION ALL, and how is UNION different from a JOIN?
EasyConcept
ConceptEasy Read the answer to What is the difference between UNION and UNION ALL, and how is UNION different from a JOIN?
3Combine Two TablesLeetCodeEasy Solve Combine Two Tables on LeetCode (opens in a new tab)
4Employees Earning More Than Their ManagersLeetCodeEasy Solve Employees Earning More Than Their Managers on LeetCode (opens in a new tab)
5Customer Who Visited but Did Not Make Any TransactionsLeetCodeEasy Solve Customer Who Visited but Did Not Make Any Transactions on LeetCode (opens in a new tab)
6Students and ExaminationsLeetCodeEasy Solve Students and Examinations on LeetCode (opens in a new tab)
7What is the difference between an equi join, a natural join, a theta join and a self join?
MediumConcept
ConceptMedium Read the answer to What is the difference between an equi join, a natural join, a theta join and a self join?
8What is a correlated subquery, and when would you use a join instead of a subquery?
MediumConcept
ConceptMedium Read the answer to What is a correlated subquery, and when would you use a join instead of a subquery?
9Managers with at Least 5 Direct ReportsLeetCodeMedium Solve Managers with at Least 5 Direct Reports on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account