更新 Woocommerce 优惠券说明 mysql

Updating Woocommerce Coupon descriptions mysql

在我的数据库中,这为我提供了正确的优惠券结果,我正在寻找

SELECT p.`ID`, p.`post_title`, p.`post_excerpt`
FROM   `wp_posts` AS p
INNER JOIN `wp_postmeta` AS pm ON  p.`ID` = pm.`post_id`
WHERE  p.`post_type` = 'shop_coupon'
AND pm.`meta_key` = 'product_ids'
AND pm.`meta_value` = '131239'

但我需要更新所有这些优惠券,超过 5k 的优惠券和标准 import/merge 不更新优惠券描述,由于我们的会计系统,我们的优惠券必须具有正确的描述,所以我需要通过 sql

更新它们
UPDATE p SET p.post_excerpt = 'emesa'
FROM wp_posts AS p
INNER JOIN wp_postmeta AS pm
ON p.ID = pm.post_id
WHERE p.post_type = 'shop_coupon'
AND pm.meta_key = 'product_ids'
AND pm.meta_value = '131239'

使用更新集不起作用。

更新查询语法与 Select 查询不同。在更新查询中,首先指定所有表(包括连接),然后使用 Set 子句。更新查询中没有使用 From

来自MySQL Documentation

UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET assignment_list [WHERE where_condition] [ORDER BY ...] [LIMIT row_count]

value: {expr | DEFAULT}

assignment: col_name = value

assignment_list: assignment [, assignment] ...

以下是正确的查询:

UPDATE wp_posts AS p
INNER JOIN wp_postmeta AS pm
ON p.ID = pm.post_id 
SET p.post_excerpt = 'emesa'
WHERE p.post_type = 'shop_coupon'
AND pm.meta_key = 'product_ids'
AND pm.meta_value = '131239'