⬅️ LEFT JOIN – Show All from the Left, Matches from the Right

(because sometimes you want everyone… even if they didn’t show up)

👀 Imagine You Have These Two Tables

🧑 employees table:

emp_idname
1Olivia
2Mason
3Zoe
4Ethan

📅 attendance table:

record_idemp_idday
20112024-04-01
20222024-04-01
20312024-04-02

You want to know who was present… but you ALSO want to see who was not.

Basically: “Show me all employees, even if they didn’t mark attendance.”

🔧 LEFT JOIN Syntax

SELECT employees.name, attendance.day
FROM employees
LEFT JOIN attendance
ON employees.emp_id = attendance.emp_id;

SQL will return all employees from the left table,
and match whatever it can from attendance. If there’s no match? You get NULL.

✅ Result

nameday
Olivia2024-04-01
Olivia2024-04-02
Mason2024-04-01
ZoeNULL
EthanNULL

Zoe and Ethan didn’t check in — but they still show up in the result.

🔁 LEFT JOIN vs INNER JOIN

TypeWho’s Shown
INNER JOINOnly employees with attendance
LEFT JOINAll employees, even without records

🧃 Recap

  • LEFT JOIN gives you all rows from the left, and matches from the right
  • If there’s no match, you get NULL
  • Use it when the left side is your focus (like “all users”, “all products”, etc.)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top