我有两个表,其中一个表与另一个表相连。我正在使用opencart,需要更新特定类别中所有产品的标题。
示例:oc_product_description
product_id
language_id
name
1
3
T-backs model 887 Róża
2
3
T-backs model 912 Róża
3
3
Push up model 3173 Róża
oc_product_to_tegory
category_id
product_id
1
1
2
1
3
1
我无法想象我应该使用什么查询。。
UPDATE oc_product_description
SET name = REPLACE(name, 'T-backs model', 'BACK')
WHERE product_id = SELECT product_id FROM oc_product_to_category WHERE category_id = 54;
更新oc_productdescriptionSET name=REPLACE(name,'T-backs model','BACK')WHERE product_id IN(SELECT product_id FROM oc_product_to_category WHERE category_id=54);
这将对你有所帮助。
如果您有更多的product_id,则应该使用where product_id in,而不是where product_id=
UPDATE oc_product_description
SET name = REPLACE(name, 'T-backs model', 'BACK')
WHERE product_id in ( SELECT product_id
FROM oc_product_to_category WHERE category_id = 54);