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

JoinReturns
INNER JOINonly matching rows in both
LEFT JOINall left rows + matches
RIGHT JOINall right rows + matches
CROSS JOINevery 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).
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp