Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #501

SQL Joins — Complete Guide

Reference Tables Used in This Section

Every join note below uses these same two tables, so you can see exactly how each join type treats the same data differently.

employees

idnamedepartment_id
1Aman1
2Riya2
3Karan1
4NehaNULL

departments

iddepartment_name
1Engineering
2Marketing
3Sales

Notice: Neha has no department (department_id is NULL), and Sales has no employees at all. These two "unmatched" rows are what make the differences between join types visible.

What a JOIN Does

A JOIN combines rows from two or more tables based on a related column between them — usually a foreign key pointing to a primary key. Without joins, related data spread across normalized tables (see Normalization) would be unusable on its own.

Basic Syntax

SELECT columns
FROM table1
JOIN_TYPE table2 ON table1.column = table2.column;

The Six Join Types at a Glance

Join TypeReturns
INNER JOINOnly rows with a match in both tables
LEFT JOINAll rows from the left table, matched or not
RIGHT JOINAll rows from the right table, matched or not
FULL OUTER JOINAll rows from both tables, matched or not
CROSS JOINEvery row from table1 paired with every row from table2
SELF JOINA table joined to itself, for hierarchical/relational data

Quick Example — INNER JOIN

SELECT e.name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.id;

Output:

namedepartment_name
AmanEngineering
RiyaMarketing
KaranEngineering

Neha (no department) and Sales (no employees) both disappear — that's the defining behavior of INNER JOIN, explored in depth on its own page.

Why Joins Matter

Real databases are normalized — customer data lives in customers, order data in orders, product data in products — precisely to avoid repeating data. Joins are how you put that data back together for reporting, dashboards, and application queries. It's arguably the single most important SQL skill for any data or backend role.

Common Mistakes

  • Forgetting the ON condition — this produces a Cartesian product (every row paired with every row), usually not what you meant. See CROSS JOIN for when that IS what you want.
  • Joining on the wrong columns (e.g. matching by name instead of ID) — fragile and can silently produce wrong matches
  • Not knowing which join type actually answers the business question — this is the #1 real-world join mistake, more common than syntax errors

Interview Relevance

Joins are the single most-tested SQL topic in interviews across analyst, data science, and backend roles. Expect at least one join question in almost every SQL round — often several.

Practice Question

Using the reference tables above, predict — without running it — which rows an INNER JOIN, a LEFT JOIN, and a FULL OUTER JOIN would each return. Then check your answer on the individual join pages.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →