Difference between = and := in MySQL

1.8k Views Asked by At

in MySQL what is the difference between these two command?

They work perfectly and the result is always the same:

set @numRecords = (select count(*) from config);

set @numRecords := (select count(*) from config);

Thanks Davide

2

There are 2 best solutions below

0
jpw On BEST ANSWER

Quoting the MySQL 5.7 Reference Manual, section 10.4 User-Defined Variables:

For SET, either = or := can be used as the assignment operator.

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 the latter is treated as the comparison operator = in non-SET statements

0
Robert Columbia On

"=" is ambiguous and could be a comparison operator. ":=" is always interpreted as an assignment operator. This information can be found at http://dev.mysql.com/doc/refman/5.7/en/assignment-operators.html .