In SQL, JOINs are used to combine rows from two or more tables based on related columns — often using primary and foreign keys.
Here’s a breakdown of the most common JOIN types:
Returns only the rows that have matching values in both tables.
Example: Show students who are enrolled in at least one course.
SELECT * FROM students
INNER JOIN enrollments
ON students.id = enrollments.student_id;Returns all rows from the left table and any matching rows from the right table. If there's no match, you'll still get the left table's data, with NULLs for the missing right side.
SELECT * FROM students
LEFT JOIN enrollments
ON students.id = enrollments.student_id;Returns all rows from the right table and any matching rows from the left table.
SELECT * FROM students
RIGHT JOIN enrollments
ON students.id = enrollments.student_id;Returns all rows from both tables, with NULLs where there’s no match on either side. (Note: Not all databases support this directly.)
SELECT * FROM students
FULL OUTER JOIN enrollments
ON students.id = enrollments.student_id;Use the Tables tab to explore how these tables relate, and try running each JOIN to see how the results differ.