The AND operator in MySQL connects Boolean expressions and returns true if and only if all expressions are true, otherwise it returns false. It is used to narrow query results, find records that meet multiple criteria, or exclude records that do not meet criteria.
Usage of AND in MySQL
The AND operator in MySQL is used to connect two or more Boolean An expression that produces a result that returns TRUE or FALSE. The result is TRUE if and only if all connected expressions are TRUE. Otherwise, the result is FALSE.
Syntax
<code>表达式1 AND 表达式2 ...</code>
Example
<code>SELECT * FROM users WHERE age > 18 AND gender = 'male';</code>
This query will retrieve all user records that are older than 18 years old and whose gender is male .
Priority
The AND operator has lower precedence than the OR operator and higher than the NOT operator.
Truth table
Expression 1 | Expression 2 | Result |
---|---|---|
TRUE | TRUE | TRUE |
TRUE | FALSE | FALSE |
FALSE | TRUE | FALSE |
FALSE | FALSE | FALSE |
Usage scenarios
AND operator is usually used to narrow the query result. For example:
Note
The above is the detailed content of How to use and in mysql. For more information, please follow other related articles on the PHP Chinese website!