CPCODELAB
SQL

WHERE — Filtering Rows

8 min read

Filtering with WHERE

The WHERE clause filters the rows returned by a query. Only rows for which the condition evaluates to TRUE are included in the result.

sql
-- Students from Mumbai
SELECT name, city FROM students WHERE city = 'Mumbai';

-- Students aged 18 or older
SELECT name, age FROM students WHERE age >= 18;

-- Courses priced below 1000
SELECT title, price FROM courses WHERE price < 1000;

Comparison Operators

  • = equal to
  • <> or != not equal to
  • < less than
  • > greater than
  • <= less than or equal to
  • >= greater than or equal to

Never use = to compare against NULL. Use IS NULL or IS NOT NULL instead — we cover this in a dedicated lesson.

Ready to test yourself?
Practice SQL— quiz & coding exercises