What is the difference between INNER JOIN and LEFT JOIN?
| JOIN | Returns |
|---|---|
INNER JOIN | Only the rows that match in both tables |
LEFT JOIN | All rows of the left table, and the matching rows of the right table (NULL if none) |
SELECT s.name, c.course_name
FROM students s
LEFT JOIN courses c ON s.course_id = c.id
WHERE s.id IN (1, 5)
ORDER BY s.id;
Tutorials Class - Output Window
| name | course_name |
|---|---|
| Robin | Python |
| Vikram | NULL |
Vikram has no course. With INNER JOIN he would not appear at all. See MySQL JOINs.
Learn more about the similar topics:
| Tutorials |
|---|
| MySQL JOINs |
| MySQL Subqueries |
| MySQL UNION |