Sometimes when developing plugins or testing things on a WordPress website, you may end up some ghost or orphaned postmeta – and no posts.
This will delete all postmeta, where the post does not exist any more.
DELETE FROM `wp_postmeta` WHERE wp_postmeta.post_id NOT IN (SELECT id FROM `wp_posts`)
If you need to delete the post and the postmeta via phpMyAdmin, you could use the following: Delete the postmeta first, then the post by post type or whatever your conditions may be. In this example I have chosen to delete posts and postmeta if its post_type is a product.
# Deletes ALL postmeta WHERE the post_type IS a product
DELETE FROM `wp_postmeta` WHERE wp_postmeta.post_id IN (SELECT id FROM `wp_posts` WHERE post_type = 'product')
# This THEN deletes ALL posts WHERE post_type IS a product
DELETE FROM `wp_posts` WHERE post_type = 'product'