Reputation: 65
I am trying to update prices in WooCommerce based on SKU. I have written some SQL but getting error 'You can't specify target table 'wp_postmeta' for update in FROM clause'. Is there any way to do the following better?
UPDATE wp_postmeta SET meta_value = 144 WHERE
meta_key = '_regular_price' AND
post_id IN(SELECT post_id FROM wp_postmeta WHERE meta_key = '_sku'
AND meta_value = SKU1451E51);
Upvotes: 2
Views: 677
Reputation: 11861
UPDATE wp_postmeta as pm
INNER JOIN wp_postmeta as pm2 on pm.post_id = pm2.post_id
SET pm.meta_value = 144
WHERE pm.meta_key = '_regular_price'
AND pm2.meta_key = '_sku'
AND pm2.meta_value = 'SKU1451E51'
Upvotes: 1