Sometimes you run into a time where you need to go into the database and delete items from the posts table. So after doing this you could have a lot of extra data getting stored in the postmeta table that is no longer needed. This is a simple MySQL command that can be run to clean this data up and optimize your database. It checks to see if the post ID is still in the posts table for the postmeta information and if it does not then it deletes it.
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL;