Last active
November 25, 2020 16:44
-
-
Save atxiii/7ff6633312fe5b42c7843ad7c0d3ff9a to your computer and use it in GitHub Desktop.
Delete Duplicate postmeta in woocommerce by sql command.
This file contains 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
create temporary table tmpTable (meta_id bigint); | |
Insert into tmpTable (meta_id) | |
select meta_id | |
from wp_postmeta pt | |
where exists | |
( | |
select * | |
from wp_postmeta pt2 | |
where pt2.post_id= pt.post_id | |
and pt2.meta_key= pt.meta_key | |
and pt2.meta_value= pt.meta_value | |
); | |
DELETE FROM wp_postmeta USING wp_postmeta, tmpTable WHERE wp_postmeta.meta_id=tmpTable.meta_id | |
-- Method 2 | |
create temporary table tmpTable (meta_id bigint); | |
Insert into tmpTable (meta_id) | |
SELECT meta_id | |
FROM wp_postmeta | |
GROUP BY post_id,meta_key,meta_value | |
HAVING COUNT(*) > 1; | |
DELETE FROM wp_postmeta USING wp_postmeta , tmpTable WHERE wp_postmeta.meta_id=tmpTable.meta_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment