PyCodeItPython trace & interview prep
DashboardMastery MapSQL PracticeDailyInterviewCompaniesBlogLeaderboardCommunity
Learning Center/sql
sql

SQL Joins Explained for Technical Interview Candidates

Inner, left, right, and full outer joins - understand what rows survive and why before your next data round.

AA

Ameer Abdullah

Data Science Graduate · AI/ML & Data Science

6 min read

Concept in Simple Words: Joins combine columns from two tables based on a matching key. Think of INNER JOIN as the overlap in a Venn diagram; only rows that match on BOTH sides survive. LEFT JOIN keeps everything from the left table; if there is no match on the right, it fills the right columns with NULL. RIGHT JOIN does the opposite. FULL JOIN keeps all rows from both tables, filling mismatches on either side with NULL.

Deep Walkthrough & Code: Let's look at a LEFT JOIN comparing employee departments, and how a NULL key handles matches:

SELECT e.name, d.dept_name
FROM employees e
LEFT JOIN departments d ON e.dept_id = d.id
ORDER BY e.name;
Step-by-Step Dry Run: Suppose we have Employees: [Alice (dept_id=1), Bob (dept_id=NULL)] and Departments: [1 (Engineering)].
- Trace Alice: dept_id=1 matches Department id=1. Alice, Engineering is returned.
- Trace Bob: dept_id=NULL. NULL never equals anything, not even another NULL. LEFT JOIN preserves Bob, but department details are filled with NULL: Bob, NULL is returned.
Bob would be excluded entirely in an INNER JOIN.

Production Level Issue & Fix: A common production trap is filtering the right table columns in the WHERE clause of a LEFT JOIN: `WHERE d.dept_name = 'Engineering'`. This implicitly converts the LEFT JOIN into an INNER JOIN because rows with NULL on the right are filtered out by the WHERE condition. The fix is to place the filter condition inside the ON clause instead: `LEFT JOIN departments d ON e.dept_id = d.id AND d.dept_name = 'Engineering'`.

Practice what you just learned

Apply these concepts in PyCodeIt's interactive sandbox with real problems.

Open SQL Sandbox

Related SQL Tutorials

  • Window Functions in SQL: RANK, ROW_NUMBER, and LEAD Explained

    Read tutorial

  • CTEs vs Subqueries: When to Use Each and Why It Matters

    Read tutorial

  • GROUP BY and HAVING: The Misconceptions That Cause Wrong Answers

    Read tutorial

PyCodeIt

Free interactive learning platform for Python code tracing, SQL queries, and technical interviews. Built for bootcamp grads, computer science students, and engineers.

Python Practice

  • Learning Center
  • For loop tracing
  • List tracing
  • Dictionary tracing
  • Decorators practice
  • Python Tracing Guide
  • Python Output Questions

SQL Practice

  • SQL Fundamentals
  • Relational JOINs
  • Window Functions
  • CTEs & Set Operators
  • SQL JOINs Guide
  • Window Functions Guide

Legal

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 PyCodeIt. Sandbox keys are processed strictly client-side.