InterviewTreedInterviewTreed
All interview questions
SQL ServerBeginner4 min read

What is the difference between INNER JOIN and LEFT JOIN?

Understand how INNER JOIN and LEFT JOIN return matching and non-matching rows.

Answer

INNER JOIN returns only rows where the join condition matches in both tables. LEFT JOIN returns every row from the left table and matching rows from the right table; when there is no match, columns from the right table are returned as NULL.

For example, joining Customers to Orders with an INNER JOIN returns customers that have matching orders. A LEFT JOIN can return all customers, including those who have never placed an order.

Be careful when filtering columns from the right table in the WHERE clause after a LEFT JOIN. A predicate that rejects NULL values may unintentionally remove unmatched rows and make the result behave like an inner join for that condition.

Code example

SELECT c.CustomerId, c.Name, o.OrderId
FROM dbo.Customers AS c
LEFT JOIN dbo.Orders AS o
    ON o.CustomerId = c.CustomerId;

Key points to remember

  • INNER JOIN returns matching rows only.
  • LEFT JOIN preserves all rows from the left table.
  • Unmatched right-side columns become NULL.
  • Understand the difference between ON and WHERE filters.

Keep practising

Understanding beats memorization.

Explain the concept in your own words, then think through how you would use it in a real project.

AI-powered mock interview practice is planned for a future release.