In our last session, you learned to select columns and create aliases. But what if your books table has 10,000 books and you only want fantasy novels?
Without filtering, you'd get all 10,000 rows when you only need a few dozen.
Engagement Message
On which website do you usually hit the 'Filter' button?
The WHERE clause solves this by filtering rows based on conditions you specify. It acts like a gatekeeper, only letting through rows that meet your criteria.
Think of WHERE as asking "only show me rows where this condition is true."
Engagement Message
What condition might help you find only expensive books?
Here's the basic WHERE structure:
This returns only books that cost exactly $19.99. The equals sign (=) checks for exact matches.
Engagement Message
What would happen if no books cost exactly $19.99?
You can also use greater than (>) and less than (<) for numeric comparisons:
These find expensive books (over $20) or budget books (under $15).
Engagement Message
Which operator finds books that cost more than $10?
The not equals operator (<>) finds everything except what you specify:
This returns all books except romance novels.
Engagement Message
What would this query return: WHERE price <> 0
?
