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 ...

Get MySQL for Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.