Home > Database > Mysql Tutorial > Why does MySQL evaluate 'TRUE or TRUE and FALSE' as true?

Why does MySQL evaluate 'TRUE or TRUE and FALSE' as true?

王林
Release: 2023-09-04 21:29:02
forward
1324 people have browsed it

为什么 MySQL 将“TRUE 或 TRUE 和 FALSE”评估为 true?

MySQL evaluates "TRUE or TRUE and FALSE" as true because AND has a higher priority than OR, i.e. AND is evaluated before OR.

MySQL evaluates the above statement as follows. The AND operator −

(TRUE or (TRUE AND FALSE))
Copy after login

statement (TRUE AND FALSE) is evaluated first and the result is FALSE. Then the second statement The evaluation is as follows -

(TRUE or FALSE)
Copy after login

The above statement gives a result of TRUE.

Let’s implement it one by one-

mysql> select (TRUE AND FALSE);
+------------------+
| (TRUE AND FALSE) |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)
Copy after login

Now we can put the above result in place of AND condition−

mysql> select (TRUE or FALSE);
+-----------------+
| (TRUE or FALSE) |
+-----------------+
|               1 |
+-----------------+
1 row in set (0.00 sec)
Copy after login

Now check the whole condition again−

mysql> select (TRUE or TRUE and FALSE);
Copy after login

This will produce the following output−

+--------------------------+
| (TRUE or TRUE and FALSE) |
+--------------------------+
|                        1 |
+--------------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of Why does MySQL evaluate 'TRUE or TRUE and FALSE' as true?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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