Can anyone explain the differences between following two requests:
SET @foundnow=0;
SELECT id, (@foundnow:=IF(`id`=3,1,0)) as ff
FROM `sometable`
HAVING @foundnow=0
result is
id ff
1 0
2 0
3 1
and
SET @foundnow=0;
SELECT id, (@foundnow:=IF(`id`=3,1,0)) as ff
FROM `sometable`
HAVING ff=0
result is
id ff
1 0
2 0
4 0
5 0
...
why first gives all rows up to id=3 (including), and second - all rows EXCEPT with id=3?
I guess related to this question is "unexpected" behavior of following request
SET @tot=0;
SELECT @tot:=@tot+1 as `ff`
FROM `anytable`
HAVING (`ff`>10)
which gives rows with ff=12,14,16,18...