MySQL + SQL · Lesson 65
Joins in MySQL
What is a JOIN?
A JOIN combines rows from two or more tables based on a related column (usually a foreign key). This is how relational databases connect data.
Our Two Tables
students(roll_no, name, class_id)
classes(class_id, class_name)
Types of Joins
| Join | Returns |
|---|---|
| INNER JOIN | only matching rows in both |
| LEFT JOIN | all left rows + matches |
| RIGHT JOIN | all right rows + matches |
| CROSS JOIN | every combination |
Inner Join Example
SELECT students.name, classes.class_name
FROM students
INNER JOIN classes ON students.class_id = classes.class_id;Lists each student with their class name, matching on class_id.
Summary
- JOIN connects tables on a related column.
- INNER (matches only), LEFT/RIGHT (keep one side), CROSS (all combos).
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.