Last active
July 9, 2024 03:28
-
-
Save yanknudtskov/035dbb2bcfacf8afa76b63d4ca6735aa to your computer and use it in GitHub Desktop.
Select Duplicate SKUs from WooCommerce Database #woocommerce #mysql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SELECT any post_status | |
SELECT meta_value,COUNT(meta_value),GROUP_CONCAT(DISTINCT post_id ORDER BY post_id SEPARATOR ',') post_id | |
FROM wp_postmeta | |
WHERE meta_key = '_sku' | |
AND meta_value != '' | |
GROUP BY meta_value HAVING COUNT(meta_value) > 1 | |
# SELECT only from products that are already published or in draft | |
SELECT meta_value,COUNT(meta_value),GROUP_CONCAT(DISTINCT post_id ORDER BY post_id SEPARATOR ',') post_id | |
FROM wp_postmeta | |
WHERE meta_key = '_sku' | |
AND meta_value != '' | |
AND post_id IN (SELECT ID FROM wp_posts WHERE post_status IN('draft', 'publish')) | |
GROUP BY meta_value HAVING COUNT(meta_value) > 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wp_postmeta might contain orphan postmeta values from deleted records in wp_posts