Home > Database > Mysql Tutorial > What is the usage of and in mysql

What is the usage of and in mysql

WBOY
Release: 2022-01-05 10:41:47
Original
7435 people have browsed it

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

What is the usage of and in mysql

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.

What is the usage of and in mysql

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template