简体   繁体   中英

Difference between = and := in MySQL

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

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

"=" 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM