LINK: https://dev.mysql.com/doc/refman/5.7/en/user-variables.html
I was reading mysql documentation and I got really confused about that general rule!
Documentation:
As a general rule, OTHER THAN IN SET statements, you should never assign a value to a user variable and read the value within the same statement.
Ok, so does it means that I can use SET statement to assign AND READ a user variable? right? BUT when I try it...
SET @a:=1, @b:=@a+1;
SELECT @a,@b; # @a = 1, @b = NULL
Looks like the SET statement have the same problem of any other statement for assign and read user variables in the same statement.
SET @a:=1;
SET @b:=@a+1;
SELECT @a,@b; # @a=1 , @b=2
So, what am I missing here?