Bug #78522 select 3 < 2 < 1
Submitted: 22 Sep 2015 21:17 Modified: 22 Sep 2015 22:29
Reporter: Don Cohen Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.5.35-log OS:Any
Assigned to: CPU Architecture:Any

[22 Sep 2015 21:17] Don Cohen
Description:
Does this make sense?  If so explain why.
> select 3 < 2 < 1; 
+-----------+ 
| 3 < 2 < 1 | 
+-----------+ 
|         1 | 
+-----------+ 
1 row in set (0.00 sec) 

I'd have thought it would be illegal syntax.

How to repeat:
type in the query again
[22 Sep 2015 21:41] Todd Farmer
I think this makes sense when order of operations are applied:

(3 < 2) < 1
( 0 ) < 1
1 # true

This can be tested by reversing the order:

mysql> select 1 > 2 > 3;
+-----------+
| 1 > 2 > 3 |
+-----------+
|         0 |
+-----------+
1 row in set (0.00 sec)

( 1 > 2 ) > 3
( 0 ) > 3
0 # false

As far as syntax, it's all just operations that evaluate to a constant.
[22 Sep 2015 21:42] Todd Farmer
It would make less sense if MySQL didn't implicitly convert data types (e.g., boolean to integer).
[22 Sep 2015 22:29] Don Cohen
ok, this (a < b) < c is what I was missing.
I accidentally had two <'s in an expression and was surprised that it meant anything at all.
BTW, where should I have looked for documentation that explains this?
I tried looking under <