Interview Databases & Caching

What is the difference between an INNER JOIN and a LEFT JOIN?

Databases & Caching · Intermediate level

Answer

An INNER JOIN returns only matching rows from both tables. A LEFT JOIN returns every row from the left table and matching right-table rows, with NULLs when no right-side match exists.

Technical explanation

INNER JOIN filters to rows that match on both sides.

LEFT JOIN preserves all left-table rows and fills right-side columns with NULL when no match exists.

Putting right-table filters in WHERE can accidentally turn a LEFT JOIN into an INNER JOIN.

Hands-on example

Find customers with no orders:

SELECT c.id, c.email FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE o.id IS NULL;

Support it with:

CREATE INDEX CONCURRENTLY idx_orders_customer_id ON orders(customer_id);

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Databases & Caching interview questions

← All Databases & Caching questions