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))
statement (TRUE AND FALSE) is evaluated first and the result is FALSE. Then the second statement The evaluation is as follows -
(TRUE or FALSE)
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)
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)
Now check the whole condition again−
mysql> select (TRUE or TRUE and FALSE);
This will produce the following output−
+--------------------------+ | (TRUE or TRUE and FALSE) | +--------------------------+ | 1 | +--------------------------+ 1 row in set (0.00 sec)
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!