In mysql, and is often used in the where sub-statement to combine two or more conditions. True will be returned only when multiple conditions evaluate to true. The syntax is "WHERE Condition 1 AND Condition 2".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
What is the usage of and in mysql
The AND operator is a logical operator that combines two or more Boolean expressions. Only Returns true only when both expressions evaluate to true. The AND operator returns false if one of the two expressions evaluates to false.
WHERE boolean_expression_1 AND boolean_expression_2SQL
The following describes the results when the AND operator combines true, false and null.
AND operator is usually used in the WHERE clause of SELECT, UPDATE, DELETE statements to form Boolean expressions. The AND operator is also used in the join conditions of INNER JOIN or LEFT JOIN clauses.
When evaluating an expression with the AND operator, MySQL evaluates the remainder of the expression until the result can be determined. This feature is called short-circuit evaluation. See the following examples.
SELECT 1 = 0 AND 1 / 0 ;Shell
When executing the above query, I get the following results -
mysql> SELECT 1 = 0 AND 1 / 0 ; +-----------------+ | 1 = 0 AND 1 / 0 | +-----------------+ | 0 | +-----------------+ 1 row in setShell
Please note that in MySQL, 0 is considered false and non-zero is considered true.
MySQL only evaluates the first part of the expression 1 = 0 AND 1/0 1 = 0. Because the expression 1 = 0 returns false, MySQL concludes that the result of the entire expression is false. MySQL does not evaluate the remainder of the expression, i.e. 1/0; if 1/0 were evaluated, it would issue an error message because of a divide-by-zero error.
Recommended learning: mysql video tutorial
The above is the detailed content of What is the usage of and in mysql. For more information, please follow other related articles on the PHP Chinese website!