Actually, they are both assignment operators, used to assign values, but the significant differences between them are as follows-
= operator assignment is Part of a SET statement or as part of the SET clause in an UPDATE statement, and in any other case the = operator is interpreted as a comparison operator. On the other hand, the := operator assigns a value and is never interpreted as a comparison operator.
mysql> Update estimated_cost1 SET Tender_value = '8570.000' where id = 2; Query OK, 1 row affected (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> Update estimated_cost1 SET Tender_value := '8575.000' where id = 2; Query OK, 1 row affected (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 0
In the above two queries, we used the = operator and the := operator to update the table values.
mysql> Set @A = 100; Query OK, 0 rows affected (0.01 sec) mysql> Select @A; +------+ | @A | +------+ | 100 | +------+ 1 row in set (0.00 sec) mysql> Set @B := 100; Query OK, 0 rows affected (0.00 sec) mysql> Select @B; +------+ | @B | +------+ | 100 | +------+ 1 row in set (0.00 sec)
In the above two queries, we use = operator and := operator to assign values to user variables. We can see that = operator and := operator have the same usage and functionality in both cases. But in the following query = operator is used as comparison operator and gives the result as "TRUE" i.e. user variables @A and @B have the same value.
mysql> Select @A = @B; +---------+ | @A = @B | +---------+ | 1 | +---------+ 1 row in set (0.00 sec)
The above is the detailed content of What is the difference between = and := assignment operators?. For more information, please follow other related articles on the PHP Chinese website!