First run some selects statement before you start deleting
SELECT * FROM wp_posts where post_status like '%XXXXXXXX%'
SELECT * FROM wp_postmeta WHERE NOT EXISTS ( SELECT * FROM wp_posts WHERE wp_postmeta.post_id = wp_posts.ID );
Run the actual delete (Always do a backup first)
delete * from wp_posts post_status like '%XXXXXXXX%' -- Delete orphan records from the wp_postmeta table delete * FROM wp_postmeta WHERE NOT EXISTS ( SELECT * FROM wp_posts WHERE wp_postmeta.post_id = wp_posts.ID );