我有一个 mysql 表。
我想使用 php 将一个值从一列“剪切并粘贴”到另一列。像这样:
mysql_query("UPDATE table1 SET a1=a2,a2='' WHERE colid=3 LIMIT 1");
是否可以仅使用上面的一条语句来完成此操作?
“SET”部分中使用的元素的顺序重要吗?
如果这不好,最有效的方法是什么?
最佳答案
来自the docs :
The second assignment in the following statement sets col2 to the current (updated) col1 value, not the original col1 value. The result is that col1 and col2 have the same value. This behavior differs from standard SQL.
UPDATE t1 SET col1 = col1 + 1, col2 = col1;
Single-table UPDATE assignments are generally evaluated from left to right. For multiple-table updates, there is no guarantee that assignments are carried out in any particular order.
关于php - MYSQL移动命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6439948/