Skip to content

Instantly share code, notes, and snippets.

@JAW-Dev
Created April 8, 2020 13:58
Show Gist options
  • Save JAW-Dev/7ecd66477926dc25ae427220248ad305 to your computer and use it in GitHub Desktop.
Save JAW-Dev/7ecd66477926dc25ae427220248ad305 to your computer and use it in GitHub Desktop.
Low Stock
SELECT p.post_title as 'Name', pm.meta_value as 'SKU', pm2.meta_value as 'Stock'
FROM wp_posts p
INNER JOIN wp_postmeta pm
ON p.ID = pm.post_id
INNER JOIN wp_postmeta pm2
ON p.ID = pm2.post_id
AND pm.meta_key = '_sku'
AND ((pm2.meta_key = '_stock' AND CAST(pm2.meta_value AS SIGNED) BETWEEN '1' AND '4' ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment