MySQL - true/false query returning different on two servers

mysql, sql

Solution

You should check the `HIGH_NOT_PRECEDENCE` operator.

The official documentation states:

The precedence of the NOT operator is such that expressions such as NOT a BETWEEN b AND c are parsed as NOT (a BETWEEN b AND c). In some older versions of MySQL, the expression was parsed as (NOT a) BETWEEN b AND c. The old higher-precedence behavior can be obtained by enabling the HIGH_NOT_PRECEDENCE SQL mode.

Fiddle to test this behaviour here.

By the way, I would recommend to compare `x != y` rather than using `not (x = y)`.

Problem

Confused on this one. Same version of MySQL running on both servers. (built from exact same rpm's) - somewhere along the line some developer changed something... Server 1: ``` mysql> select ( not 1 = 2 ); 0 1 row in set (0.00 sec) ``` Server 2: ``` mysql> select ( not 1 = 2 ); 1 1 row in set (0.00 sec) ``` Both servers: ``` mysql> sHOW VARIABLES LIKE 'version'; | version | 5.6.12 | ```

Original source