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
- What is a transaction, and what do the ACID properties mean?
- What is WAL (write-ahead logging), and how does it support durability and replication?
- What is a deadlock, and how do databases detect and resolve them?
- What is AWS DMS, and when would you use it?
- What is schema migration, and how do you run migrations safely in production?
- What is connection exhaustion, and how do you prevent it?
- What is ElastiCache, and what does it manage?
- What is a composite index, and does column order matter?