Left Join

SQL · Joining Multiple Tables

Theory

LEFT JOIN (LEFT OUTER JOIN) keeps every row from the left table, the one written first, and adds matching data from the right table. When a left row has no match, it still appears once, with NULL in all of the right table's columns. Matched rows behave exactly as in an INNER JOIN.

This makes LEFT JOIN the standard tool for finding missing relationships: LEFT JOIN orders and then WHERE o.order_id IS NULL lists customers who never ordered (an anti-join). Be careful where you put filters on the right table. A condition in ON only limits which right rows match, while the same condition in WHERE removes the NULL rows and quietly turns the query back into an INNER JOIN.

Why we use it

Business questions often need every item from a main list, even when related data is missing: all employees with their department if any, all customers with their orders if any. LEFT JOIN keeps the complete main list.

When to use it

Use LEFT JOIN when the left table is your main list and right-side data is optional, or to find unmatched rows with IS NULL. Use INNER JOIN when unmatched rows should be excluded.

How it works

  1. Take a row from the left table
  2. Look for right rows that satisfy the ON condition
  3. Any match? Yes: One combined row per match. No: Left row once, NULLs on the right.
  4. Repeat for every left row
  5. Return all left rows

Syntax

SELECT columns
FROM t1
LEFT JOIN t2 ON t1.id = t2.t1_id;

Example

SELECT e.name, d.department_name
FROM employees e
LEFT JOIN departments d ON e.dept_id = d.id;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic