I expected this query to return all columns as 0, how is the right expression 1?
select (not(55))=1, !(55)=1, not(55)=1 ;
+-------------+---------+-----------+
| (not(55))=1 | !(55)=1 | not(55)=1 |
+-------------+---------+-----------+
| 0 | 0 | 1 |
+-------------+---------+-----------+
I find this surprising that NOT and ! aren't equivalent, and that the parens are significant.
[edit: simplified the query from original post]
It appears to me what you are seeing is that the comparison
=operator has higher precedence than theNOToperator:NOT( IFNULL(55,0)) = 1is equivalent toNOT (IFNULL(55,0)=1)(NOT( IFNULL(55,0))) = 1is equivalent to(NOT IFNULL(55,0)) = 1!(IFNULL(55,0)) = 1is equivalent to exactly what is looks like; and indicates!has higher or equal precedence to=.Which is corroborated by the official docs here.
I would guess the different precedence of
!andNOThas something to do with the slightly different semantics and expected uses of the two operators. I've never tried, but I am pretty surex IS !NULLandx ! IN ([set])are not permitted.