Available Tables

Next →

LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, INNER JOIN

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:

INNER JOIN

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;

LEFT JOIN

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;

RIGHT JOIN

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;

FULL OUTER JOIN

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.