All SQL topics
SQL TOPIC

SQL WHERE: filter rows with conditions

WHERE keeps only the rows that match your conditions, before anything is counted or summed.

Combine conditions with AND (both must be true) and OR (either is enough). Wrap OR conditions in brackets when mixing them with AND so the logic reads the way you mean it.

Text values go in single quotes and are compared exactly, so 'Germany' and 'germany' are different.

Worked example

Which business customers are based in Germany?

SELECT name, city
FROM customers
WHERE country = 'Germany'
  AND segment = 'business';
Result on the sample data
namecity
Jonas BeckerBerlin

Common mistakes

  • Mixing AND and OR without brackets.
  • Using double quotes for text: in SQL they usually mean a column name.