School DB Lab
Which rows survive?

JOIN Visualizer

Two small, real tables — six students and their enrollments — used to show exactly which rows an INNER JOIN drops and a LEFT JOIN keeps.

دو چھوٹے اور حقیقی ٹیبلز — چھ طلبہ اور ان کے داخلے (Enrollments) — جن کے ذریعے واضح طور پر دکھایا گیا ہے کہ ایک اِنر جوائن (INNER JOIN) کن ریکارڈز کو چھوڑ دیتا ہے اور لیفٹ جوائن (LEFT JOIN) کن ریکارڈز کو محفوظ رکھتا ہے۔

students (source)

student_idName
15 Bilawal Chaudhry
16 Sana Rafiq
17 Yusuf Anwar
18 Amna Riaz
19 Talha Nadeem (no enrollment)
20 Hira Basit (no enrollment)

student_enrollments (source)

student_id (FK)class_id (FK)
153
164
174
184

INNER JOIN

SELECT s.*, e.class_id
FROM students s
INNER JOIN student_enrollments e
  ON e.student_id = s.student_id;
student_idNameclass_id
15Bilawal Chaudhry3
16Sana Rafiq4
17Yusuf Anwar4
18Amna Riaz4

4 row(s). Students with no enrollment row disappeared entirely.

LEFT JOIN

SELECT s.*, e.class_id
FROM students s
LEFT JOIN student_enrollments e
  ON e.student_id = s.student_id;
student_idNameclass_id
15Bilawal Chaudhry 3
16Sana Rafiq 4
17Yusuf Anwar 4
18Amna Riaz 4
19Talha Nadeem NULL
20Hira Basit NULL

6 row(s) — every student from the left table is kept, with NULL filled in where no match exists.

Three-table JOIN: students → student_enrollments → classes

SELECT s.first_name, c.class_name, c.section
FROM students s
JOIN student_enrollments e ON e.student_id = s.student_id
JOIN classes c ON c.class_id = e.class_id;
student_idStudentenrollment.class_idclasses.class_idClass
1 Ali 1 1 Grade 5 - A
2 Sara 1 1 Grade 5 - A
3 Bilal 1 1 Grade 5 - A
4 Ayesha 1 1 Grade 5 - A
5 Hamza 1 1 Grade 5 - A
6 Zainab 2 2 Grade 5 - B

The two highlighted columns are the same value — that matching pair is the entire mechanism the JOIN uses to line up rows from two different tables.

Explain this page
INNER JOIN vs LEFT JOIN, in one sentence
INNER JOIN keeps only rows that have a match on both sides. LEFT JOIN keeps every row from the left (first) table regardless, filling in NULLs when there's no match.
INNER JOIN بمقابلہ LEFT JOIN — ایک جملے میں
اِنر جوائن (INNER JOIN) صرف وہ ریکارڈز رکھتا ہے جن کا دونوں ٹیبلز میں مطابقت ہو۔ لیفٹ جوائن (LEFT JOIN) بائیں (پہلے) ٹیبل کی ہر قطار کو برقرار رکھتا ہے، اور جہاں مطابقت نہ ہو وہاں NULL بھر دیتا ہے۔