很久以前,我在这里发现了一个非常相似的话题,当时发帖人正在寻求一种方法来退还WooCommerce中所有没有缩略图(即没有图像)的产品。
那很好,但是我还想返回的是产品的SKU,它也存在于wp_postmeta表中。
如何调整下面的查询以返回该查询?
谢谢!
SELECT p.ID, p.post_title
FROM wp_posts as p LEFT OUTER JOIN wp_postmeta pm ON (p.ID=pm.post_id AND pm.meta_key = '_thumbnail_id')
WHERE p.post_type = 'product' AND (meta_key IS NULL OR meta_value = "")
答案 0 :(得分:0)
想想我在弄乱后已经回答了我自己的问题!
SELECT wp_posts.ID, wp_posts.post_title, wp_postmeta1.meta_value as SKU
FROM wp_posts
LEFT OUTER JOIN wp_postmeta pm ON (wp_posts.ID=pm.post_id AND pm.meta_key = '_thumbnail_id')
LEFT JOIN wp_postmeta wp_postmeta1 on wp_postmeta1.post_id = wp_posts.ID and wp_postmeta1.meta_key = '_sku'
WHERE wp_posts.post_type = 'product' AND (pm.meta_key IS NULL OR pm.meta_value = "")