SQL Tutorial
SQL Joins
Combine related tables with INNER JOIN and OUTER JOIN patterns.
Concept
Joins combine rows based on a relationship condition. INNER JOIN keeps matching rows, while LEFT JOIN keeps every row from the left table and fills unmatched right-side columns with nulls.
Use explicit join conditions and qualify ambiguous column names with table aliases. This makes multi-table queries easier to review.
Example
SELECT s.name, c.title
FROM enrollments e
JOIN students s ON s.student_id = e.student_id
JOIN courses c ON c.course_id = e.course_id;
Type the example yourself and change at least one value. Small experiments reveal syntax and behavior faster than passive reading.
Practice Tasks
- Join students to enrollments.
- Add the courses table to return course titles.
- Use LEFT JOIN to show students even if they have no enrollment.
Key Takeaways
- Joins connect normalized data.
- INNER and LEFT JOIN answer different questions.
- Aliases keep multi-table SQL readable.