更新特定列等于其他 table
Update specific column equal to other table
我有 2 个表,其中一个附加到另一个。
我正在使用 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_category
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;
如果你有超过 product_id 你应该使用 where product_id 而不是 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);
更新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);
这对你有帮助。
我有 2 个表,其中一个附加到另一个。 我正在使用 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_category
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;
如果你有超过 product_id 你应该使用 where product_id 而不是 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);
更新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);
这对你有帮助。