I need to update the value of pm_virtual.meta_value = 'no'
, only for those products that have pm_downloadable.meta_value = 'yes'
. How do I do this?
SELECT
p.ID,
p.post_title,
pm_downloadable.meta_value AS downloadable_trait,
pm_virtual.meta_value AS virtual_trait
FROM
xhdps_posts AS p
INNER JOIN xhdps_postmeta AS pm_downloadable ON p.ID = pm_downloadable.post_id
LEFT JOIN xhdps_postmeta AS pm_virtual ON p.ID = pm_virtual.post_id
AND pm_virtual.meta_key = '_virtual'
WHERE
p.post_type = 'product'
AND p.post_status = 'publish'
AND pm_downloadable.meta_key = '_downloadable'
AND pm_downloadable.meta_value = 'yes'
AND pm_virtual.meta_value = 'no'
2
Answers
You can use an
UPDATE`` statement along with a
JOIN` to filter the products based on the specified conditions.Just break the query to take the
XHDPS_POSTMETA
table out of theSELECT
query andUPDATE
it with relevant values as follows: