content_image/761998.jpg
## Project Results 

<img src='content_image/761998.jpg'>

## Tip 

Within a program, binding enables you to specify placeholders in your expressions, which are filled in with values before execution and can benefit from automatic escaping, as appropriate. 

Always use binding to sanitize input. Avoid introducing values in queries using string concatenation, which can produce invalid input and, in some cases, can cause security issues. 

To issue a query using the AND  operator, add the operator between search conditions in the where() method. 

mysql-py> db.city.select(["Name", "CountryCode"]).where( "Name like ’Z%’ and CountryCode = ’CHN’") +----------------+-------------+ | Name | CountryCode | +----------------+-------------+ | Zhengzhou | CHN | | Zibo | CHN | | Zhangjiakou | CHN | | Zhuzhou | CHN | | Zhangjiang | CHN | | Zigong | CHN | | Zaozhuang | CHN | ... ... | Zhangjiagang | CHN | +----------------+-------------+ 22 rows in set (0.01 sec) 

To specify multiple conditional operators, you can enclose the search conditions in parenthesis to change the operator precedence. The following example demonstrates the placement of AND  and OR  operators. 

## Limit, Order, and Offset Results 

mysql-py> db.city.select(["Name", "CountryCode"]).where( "Name like ’Z%’ and (CountryCode = ’CHN’ or CountryCode = ’RUS’)") +-------------------+-------------+ | Name | CountryCode | +-------------------+-------------+ | Zhengzhou | CHN | | Zibo | CHN | | Zhangjiakou | CHN | | Zhuzhou | CHN | ... ... | Zeleznogorsk | RUS | +-------------------+-------------+ 29 rows in set (0.01 sec) 

You can apply the limit() , order_by() , and offset()  methods to manage the number and order of records returned by the select()  method. 

To specify the number of records included in a result set, append the limit()  method with a value to the select()  method. For example, the following query returns the first five records in the country table. 

mysql-py> db.country.select(["Code", "Name"]).limit(5) +------+-------------+ | Code | Name | +------+-------------+ | ABW | Aruba | | AFG | Afghanistan | 

