[Solved] MySQL Insert into post_meta with select and join – what am I doing wrong?


I’m going to take a hot second to answer this.

My query was correct.

I simply didn’t have AutoIncrement turned on, because there was an invalid ID of 0, which I deleted.

EDIT: FINAL CORRECT QUERY

-----------------------------------------------------------------
INSERT INTO wp4t_postmeta (post_id, meta_key, meta_value)
SELECT postmeta.post_id, '_attached_image', posts.ID 
FROM wp4t_postmeta AS postmeta 
INNER JOIN wp4t_posts AS posts ON postmeta.meta_value = posts.guid 
WHERE postmeta.meta_key = '_content_field_42' 
AND posts.post_type="attachment"
-----------------------------------------------------------------

Worked on a VPS server with over 1MM tables in wp_postmeta – took some time, but it ran.

1

solved MySQL Insert into post_meta with select and join – what am I doing wrong?