我需要从表中删除重复的元值,其中重复值共享相同的 post_id。导入出错,数十万行包含大量重复值。
因此在下面的示例中,有两行的 post_id 为 12 且 meta_value 为 6,而实际上应该只有一行。
meta_id post_id meta_key meta_value
------- ------- -------- ----------
1 12 attribute_pa_length 6
2 12 attribute_pa_length 6
3 12 attribute_pa_length 9
4 35 attribute_pa_length 8
5 35 attribute_pa_length 12
最佳答案
这将为您留下较小的 meta_id
DELETE T1
FROM YourTable T1, YourTable T2
WHERE T1.post_id = T2.post_id
AND T1.meta_value = T2.meta_value
AND T1.meta_id > T2.meta_id
关于mysql - 删除具有重复值的帖子元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35875552/