我有两个表:ps_product_shop
和ps_product
。
我要使用以下命令更新ps_product_shop
中的列:
UPDATE `ps_product_shop`
SET dm_heureka_product_sk = 'Text'
AND (SELECT reference from ps_product where id_product = 508) where id_product = 508
我收到此错误:
#1292-截断了错误的DOUBLE值:“文本”
我如何插入文本+(从ps_product的id为508的SELECT引用中选择)?
“选择”命令从ps_product表和“引用”列中获取值
服务器mysql:服务器版本:5.7.24
感谢帮助。
答案 0 :(得分:1)
如果reference
对于id_product
是唯一的,则可以这样使用CONCAT()
UPDATE ps_product_shop SET dm_heureka_product_sk = CONCAT('Text', (SELECT reference from ps_product where id_product = 508) where id_product = 508
答案 1 :(得分:0)
这可以通过mysql UPDATE JOIN来实现:
UPDATE ps_product_shop pps
INNER JOIN ps_product pp ON pp.id_product = pps.id_product
SET pps.dm_heureka_product_sk = CONCAT('Text', pps.reference)
WHERE pps.id_product = 508