You can also assign a value to a user variable in statements other than SET : User Defined Variables : Select Query MySQL TUTORIALS


MySQL TUTORIALS » Select Query » User Defined Variables »

 

You can also assign a value to a user variable in statements other than SET


In this case, the assignment operator must be := and not = because = is treated as a comparison operator in non-SET statements:

mysql>
mysql> SET @t1=0, @t2=1, @t3=2;
Query OK, rows affected (0.00 sec)

mysql>
mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
+----------------------+------+------+------+
| @t1:=(@t2:=1)+@t3:=| @t1  | @t2  | @t3  |
+----------------------+------+------+------+
|                    5    1    4    |
+----------------------+------+------+------+
row in set (0.00 sec)

mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Select Query
» User Defined Variables