将字符串添加到表中现有值的更短方法

时间:2018-12-07 08:43:16

标签: php mysql

说表t1-列cnt的值为3,2,5

我想将值更改为4,3,2,5

我首先通过选择值-创建一个变量-并连接字符串-并更新表来完成此操作。

有没有更短的方法,例如:

$sql = "update t1 set cnt = '4,' plus existing value where...;

1 个答案:

答案 0 :(得分:1)

您可以在下面使用concat()函数

update t1 set cnt = concat('4,',cnt) 
where...



$sql = "update galls set cnt = concat('$id',',', cnt where...)"