Filtering with WHERE

MySQL Course · lesson 2 of 21 · 4 min read

WHERE runs before anything else, so it decides how much work the rest has to do.

Open this lesson in the learning hub

Key points

  • WHERE keeps only the rows whose condition is true - it never changes the columns.
  • Combine with AND and OR; AND binds tighter, so parenthesise when mixing.
  • LIKE with % matches any run of characters; _ matches exactly one.
  • IN (...) is shorthand for a chain of ORs on the same column.
  • NULL is not a value - use IS NULL, never = NULL, which is never true.

WHERE decides which rows survive, and doing it early is what keeps a query fast.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the MySQL Course course, and every lesson in it is listed on the MySQL Course contents page.