Loading Depth Study
Preparing your workspace
Joins combine rows from related tables using matching columns.
Relational database design often stores related information in separate tables. JOIN operations let you retrieve that information together. INNER JOIN returns rows where matching records exist in both tables. LEFT JOIN keeps all rows from the left table even when no matching row exists on the right. RIGHT JOIN represents the reverse relationship, although queries are often easier to understand by choosing the appropriate left table. Joins are one of the most important SQL skills for real applications.
A course enrollment report can join students and courses to show each student's name beside the course they enrolled in.
SELECT students.name, courses.title FROM enrollments INNER JOIN students ON enrollments.student_id = students.id INNER JOIN courses ON enrollments.course_id = courses.id;
The query returns student names together with the titles of their enrolled courses.