Use MySQL for multi-condition query
How to use MySQL for multi-condition query?
There are two main ways to perform multi-condition queries in MySQL:
1. Use the AND operator
AND operator will Multiple query conditions are combined together, and results will be returned only when all conditions are met. The syntax is as follows:
<code class="sql">SELECT column_list FROM table_name WHERE condition1 AND condition2 AND ...</code>
For example:
<code class="sql">SELECT * FROM customers WHERE age > 25 AND gender = 'male' AND city = 'New York';</code>
This query will return all customer records that are older than 25 years old, have a male gender, and live in New York City.
2. Use the OR operator
The OR operator combines multiple query conditions and returns results if any one of the conditions is met. The syntax is as follows:
<code class="sql">SELECT column_list FROM table_name WHERE condition1 OR condition2 OR ...</code>
For example:
<code class="sql">SELECT * FROM products WHERE price < 100 OR category = 'Electronics';</code>
This query will return all products whose price is less than 100 yuan or which belong to the "Electronics" category.
Note:
The above is the detailed content of How to query with multiple conditions in mysql. For more information, please follow other related articles on the PHP Chinese website!