本文介绍了SQL UPDATE带有附加字符串CONCAT的字段中的所有值不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想做的:

当前表:

+----+-------------+  
| id | data        |  
+----+-------------+  
|  1 | max         |  
|  2 | linda       |  
|  3 | sam         |  
|  4 | henry       |  
+----+-------------+  

神秘查询(类似"UPDATE table SET data = CONCAT(data, 'a')")

结果表:

+----+-------------+  
| id | data        |  
+----+-------------+  
|  1 | maxa        |  
|  2 | lindaa      |  
|  3 | sama        |  
|  4 | henrya      |  
+----+-------------+  

就是这样!我只需要在单个查询中执行此操作,但似乎找不到方法.我在bluehost上使用了mySQL(我认为它的版本是4.1)

thats it! I just need to do it in a single query, but can't seem to find a way. I am using mySQL on bluehost (I think its version 4.1)

谢谢大家.

推荐答案

这几乎是您所需要的:

mysql> select * from t;
+------+-------+
| id   | data  |
+------+-------+
|    1 | max   |
|    2 | linda |
|    3 | sam   |
|    4 | henry |
+------+-------+
4 rows in set (0.02 sec)

mysql> update t set data=concat(data, 'a');
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> select * from t;
+------+--------+
| id   | data   |
+------+--------+
|    1 | maxa   |
|    2 | lindaa |
|    3 | sama   |
|    4 | henrya |
+------+--------+
4 rows in set (0.00 sec)

尽管我正在5.1.41上对此进行测试,但不确定为什么会遇到麻烦

Not sure why you'd be having trouble, though I am testing this on 5.1.41

这篇关于SQL UPDATE带有附加字符串CONCAT的字段中的所有值不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:06