Chapter 11. SELECT Alternatives
We have already seen how to restrict the data that MySQL returns by using a WHERE
clause. Rather than retrieve the entire table and sort through it in Python, we passed the burden onto the server. Using WHERE
restricted the number of rows that match. This is just like when we specify columns instead of using an asterisk after SELECT
—it saves us from receiving the entire record for every match.
WHERE
causes MySQL to ignore any row that does not match our selection. Specifying the columns then indicates to MySQL, which parts of the affected rows to return. In addition to WHERE
, MySQL supports other ways of narrowing one's returns. It also allows us to match and complement the data using other tables, including combining tables or results from different queries.
In this chapter, we will see:
How we can restrict results using
WHERE
andHAVING
, and what the differences are between themWhen it is best to use
WHERE
and when one might useHAVING
How to create temporary...