Beginner

453. JOIN with WHERE

Understand how WHERE filters rows after tables have been joined.

📘 Lesson 453 of 728 ⏱ 11 min 🎯 Intermediate

WHERE filters the rows produced by the FROM and JOIN portions of a SQL query according to specified conditions.

Filtering joined data allows analysts to focus on the exact records required for a business question.

Return orders belonging only to customers from Mumbai.

SQL
SELECT
    c.CustomerName,
    c.City,
    o.OrderID,
    o.OrderAmount
FROM Customers c
INNER JOIN Orders o
    ON c.CustomerID = o.CustomerID
WHERE c.City = 'Mumbai';

This pattern is widely used in customer, sales, banking, employee, and transaction reporting.

  • JOIN combines related data.
  • WHERE filters the resulting rows.
  • WHERE can reference columns from joined tables.
  • Multiple WHERE conditions can be combined.
  • Filter conditions should match the business requirement.
Can WHERE reference columns from both joined tables?

Yes. WHERE can reference columns from any table included in the query.

What is the purpose of WHERE after a JOIN?

WHERE filters the joined result to keep only records that meet the required conditions.

Have you finished this lesson?

Introduction to SQL – All Lessons