When migrating from Magento 1 to Magento 2 you may encounter orphan record errors such as;
[2019-01-08 13:36:44][WARNING]: Foreign key (FK_####) constraint fails on source database. Orphan records id: 121 fromcatalog_eav_attribute
.attribute_id
has no referenced records in eav_attribute
[2019-01-08 13:36:44][WARNING]: Foreign key (FK_####) constraint fails on source database. Orphan records id: 121 from
catalog_product_entity_int
.attribute_id
has no referenced records in eav_attribute
[2019-01-08 13:36:44][WARNING]: Foreign key (FK_####) constraint fails on source database. Orphan records id: 121 from
eav_entity_attribute
.attribute_id
has no referenced records in eav_attribute
GitHub help
Using dfelton’s Magento 1.x Orphaned Records Cleanup script I was able to remove orphan records that had built up over the years. It’s always nice to feel the new Magento 2 database won’t be taking any obselete entries and old plugin clutter with it.
Remove orphan IDs SQL
Here’s my SQL for Magento 1.9x CE in full. I’ve tried to remove any theme or plugin specific entries, but remove any lines that can’t be found in your database.
Remember to perform a database backup before running the script.
DELETE FROM `admin_rule` WHERE `role_id` NOT IN (SELECT `role_id` FROM `admin_role`);
DELETE FROM `api2_acl_rule` WHERE `role_id` NOT IN (SELECT `entity_id` FROM `api2_acl_role`);
DELETE FROM `api2_acl_user` WHERE `admin_id` NOT IN (SELECT `user_id` FROM `admin_user`);
DELETE FROM `api2_acl_user` WHERE `role_id` NOT IN (SELECT `entity_id` FROM `api2_acl_role`);
DELETE FROM `api_rule` WHERE `role_id` NOT IN (SELECT `role_id` FROM `api_role`);
DELETE FROM `api_session` WHERE `user_id` NOT IN (SELECT `user_id` FROM `api_user`);
DELETE FROM `catalog_category_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_category_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_category_entity_datetime` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_category_entity_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_category_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_category_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_category_entity_int` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_category_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_category_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_category_entity_text` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_category_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_category_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_category_entity_varchar` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_category_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_category_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_category_flat_store_1` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_category_flat_store_1` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_category_product` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_category_product` WHERE `category_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_category_product_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_category_product_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_category_product_index` WHERE `category_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `catalog_compare_item` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `catalog_compare_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_compare_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_eav_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_bundle_option` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_bundle_option_value` WHERE `option_id` NOT IN (SELECT `option_id` FROM `catalog_product_bundle_option`);
DELETE FROM `catalog_product_bundle_price_index` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_bundle_price_index` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalog_product_bundle_price_index` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_bundle_selection` WHERE `option_id` NOT IN (SELECT `option_id` FROM `catalog_product_bundle_option`);
DELETE FROM `catalog_product_bundle_selection` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_bundle_selection_price` WHERE `selection_id` NOT IN (SELECT `selection_id` FROM `catalog_product_bundle_selection`);
DELETE FROM `catalog_product_bundle_selection_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_enabled_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_enabled_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_entity` WHERE `attribute_set_id` NOT IN (SELECT `attribute_set_id` FROM `eav_attribute_set`);
DELETE FROM `catalog_product_entity` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `catalog_product_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_entity_datetime` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_entity_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_entity_gallery` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_gallery` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_entity_gallery` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_entity_group_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_entity_group_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalog_product_entity_group_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_int` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_media_gallery` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_media_gallery` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_entity_media_gallery_value` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_entity_media_gallery_value` WHERE `value_id` NOT IN (SELECT `value_id` FROM `catalog_product_entity_media_gallery`);
DELETE FROM `catalog_product_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_entity_text` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_entity_tier_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_entity_tier_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_tier_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalog_product_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_entity_varchar` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_flat_1` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_index_eav` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_index_eav` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_index_eav` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_index_eav_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_index_eav_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_index_eav_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `catalog_product_index_group_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalog_product_index_group_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_index_group_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_index_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalog_product_index_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_index_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_index_tier_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalog_product_index_tier_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_index_tier_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_index_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_link` WHERE `link_type_id` NOT IN (SELECT `link_type_id` FROM `catalog_product_link_type`);
DELETE FROM `catalog_product_link` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_link` WHERE `linked_product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_link_attribute` WHERE `link_type_id` NOT IN (SELECT `link_type_id` FROM `catalog_product_link_type`);
DELETE FROM `catalog_product_link_attribute_decimal` WHERE `link_id` NOT IN (SELECT `link_id` FROM `catalog_product_link`);
DELETE FROM `catalog_product_link_attribute_decimal` WHERE `product_link_attribute_id` NOT IN (SELECT `product_link_attribute_id` FROM `catalog_product_link_attribute`);
DELETE FROM `catalog_product_link_attribute_int` WHERE `product_link_attribute_id` NOT IN (SELECT `product_link_attribute_id` FROM `catalog_product_link_attribute`);
DELETE FROM `catalog_product_link_attribute_int` WHERE `link_id` NOT IN (SELECT `link_id` FROM `catalog_product_link`);
DELETE FROM `catalog_product_link_attribute_varchar` WHERE `link_id` NOT IN (SELECT `link_id` FROM `catalog_product_link`);
DELETE FROM `catalog_product_link_attribute_varchar` WHERE `product_link_attribute_id` NOT IN (SELECT `product_link_attribute_id` FROM `catalog_product_link_attribute`);
DELETE FROM `catalog_product_option` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_option_price` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_option_price` WHERE `option_id` NOT IN (SELECT `option_id` FROM `catalog_product_option`);
DELETE FROM `catalog_product_option_title` WHERE `option_id` NOT IN (SELECT `option_id` FROM `catalog_product_option`);
DELETE FROM `catalog_product_option_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_option_type_price` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_option_type_price` WHERE `option_type_id` NOT IN (SELECT `option_type_id` FROM `catalog_product_option_type_value`);
DELETE FROM `catalog_product_option_type_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_option_type_title` WHERE `option_type_id` NOT IN (SELECT `option_type_id` FROM `catalog_product_option_type_value`);
DELETE FROM `catalog_product_option_type_value` WHERE `option_id` NOT IN (SELECT `option_id` FROM `catalog_product_option`);
DELETE FROM `catalog_product_relation` WHERE `child_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_relation` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_super_attribute` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_super_attribute_label` WHERE `product_super_attribute_id` NOT IN (SELECT `product_super_attribute_id` FROM `catalog_product_super_attribute`);
DELETE FROM `catalog_product_super_attribute_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalog_product_super_attribute_pricing` WHERE `product_super_attribute_id` NOT IN (SELECT `product_super_attribute_id` FROM `catalog_product_super_attribute`);
DELETE FROM `catalog_product_super_attribute_pricing` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalog_product_super_link` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_super_link` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_website` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalog_product_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `cataloginventory_stock_item` WHERE `stock_id` NOT IN (SELECT `stock_id` FROM `cataloginventory_stock`);
DELETE FROM `cataloginventory_stock_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `cataloginventory_stock_status` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `cataloginventory_stock_status` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `cataloginventory_stock_status` WHERE `stock_id` NOT IN (SELECT `stock_id` FROM `cataloginventory_stock`);
DELETE FROM `catalogrule_customer_group` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalogrule_customer_group` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `catalogrule`);
DELETE FROM `catalogrule_group_website` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalogrule_group_website` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `catalogrule`);
DELETE FROM `catalogrule_group_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalogrule_product` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalogrule_product` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalogrule_product` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalogrule_product` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `catalogrule`);
DELETE FROM `catalogrule_product_price` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `catalogrule_product_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalogrule_product_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `catalogrule_website` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `catalogrule`);
DELETE FROM `catalogrule_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `catalogsearch_query` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `catalogsearch_result` WHERE `query_id` NOT IN (SELECT `query_id` FROM `catalogsearch_query`);
DELETE FROM `catalogsearch_result` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `cfp_table` WHERE `id_cat` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `cfp_table` WHERE `id_prod` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `checkout_agreement_store` WHERE `agreement_id` NOT IN (SELECT `agreement_id` FROM `checkout_agreement`);
DELETE FROM `checkout_agreement_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `cms_block_store` WHERE `block_id` NOT IN (SELECT `block_id` FROM `cms_block`);
DELETE FROM `cms_block_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `cms_page_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `cms_page_store` WHERE `page_id` NOT IN (SELECT `page_id` FROM `cms_page`);
DELETE FROM `core_email_queue_recipients` WHERE `message_id` NOT IN (SELECT `message_id` FROM `core_email_queue`);
DELETE FROM `core_layout_link` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `core_layout_link` WHERE `layout_update_id` NOT IN (SELECT `layout_update_id` FROM `core_layout_update`);
DELETE FROM `core_store` WHERE `group_id` NOT IN (SELECT `group_id` FROM `core_store_group`);
DELETE FROM `core_store` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `core_store_group` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `core_translate` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `core_translate_backup` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `core_url_rewrite` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `core_url_rewrite` WHERE `category_id` NOT IN (SELECT `entity_id` FROM `catalog_category_entity`);
DELETE FROM `core_url_rewrite` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `core_variable_value` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `core_variable_value` WHERE `variable_id` NOT IN (SELECT `variable_id` FROM `core_variable`);
DELETE FROM `coupon_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `coupon_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `coupon_aggregated_updated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `customer_address_entity` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `customer_address_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_address_entity_datetime` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_address_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_address_entity`);
DELETE FROM `customer_address_entity_decimal` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_address_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_address_entity`);
DELETE FROM `customer_address_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_address_entity_int` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_address_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_address_entity`);
DELETE FROM `customer_address_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_address_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_address_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_address_entity`);
DELETE FROM `customer_address_entity_text` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_address_entity_varchar` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_address_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_address_entity`);
DELETE FROM `customer_address_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_eav_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_eav_attribute_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `customer_eav_attribute_website` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_entity` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `customer_entity` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `customer_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `customer_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_entity_datetime` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `customer_entity_decimal` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `customer_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_entity_int` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_entity_text` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `customer_entity_varchar` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `customer_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `customer_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `customer_form_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `dataflow_batch` WHERE `profile_id` NOT IN (SELECT `profile_id` FROM `dataflow_profile`);
DELETE FROM `dataflow_batch` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `dataflow_batch_export` WHERE `batch_id` NOT IN (SELECT `batch_id` FROM `dataflow_batch`);
DELETE FROM `dataflow_batch_import` WHERE `batch_id` NOT IN (SELECT `batch_id` FROM `dataflow_batch`);
DELETE FROM `dataflow_import_data` WHERE `session_id` NOT IN (SELECT `session_id` FROM `dataflow_session`);
DELETE FROM `dataflow_profile_history` WHERE `profile_id` NOT IN (SELECT `profile_id` FROM `dataflow_profile`);
DELETE FROM `design_change` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `directory_country_region_name` WHERE `region_id` NOT IN (SELECT `region_id` FROM `directory_country_region`);
DELETE FROM `downloadable_link` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `downloadable_link_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `downloadable_link_price` WHERE `link_id` NOT IN (SELECT `link_id` FROM `downloadable_link`);
DELETE FROM `downloadable_link_purchased` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `downloadable_link_purchased` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `downloadable_link_purchased_item` WHERE `purchased_id` NOT IN (SELECT `purchased_id` FROM `downloadable_link_purchased`);
DELETE FROM `downloadable_link_purchased_item` WHERE `order_item_id` NOT IN (SELECT `item_id` FROM `sales_flat_order_item`);
DELETE FROM `downloadable_link_title` WHERE `link_id` NOT IN (SELECT `link_id` FROM `downloadable_link`);
DELETE FROM `downloadable_link_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `downloadable_sample` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `downloadable_sample_title` WHERE `sample_id` NOT IN (SELECT `sample_id` FROM `downloadable_sample`);
DELETE FROM `downloadable_sample_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_attribute` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_attribute_group` WHERE `attribute_set_id` NOT IN (SELECT `attribute_set_id` FROM `eav_attribute_set`);
DELETE FROM `eav_attribute_label` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `eav_attribute_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_attribute_option` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `eav_attribute_option_value` WHERE `option_id` NOT IN (SELECT `option_id` FROM `eav_attribute_option`);
DELETE FROM `eav_attribute_option_value` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_attribute_set` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_entity` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity_attribute` WHERE `attribute_group_id` NOT IN (SELECT `attribute_group_id` FROM `eav_attribute_group`);
DELETE FROM `eav_entity_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `eav_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `eav_entity`);
DELETE FROM `eav_entity_datetime` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_entity_datetime` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity_decimal` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `eav_entity`);
DELETE FROM `eav_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `eav_entity`);
DELETE FROM `eav_entity_int` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity_int` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_entity_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_entity_store` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity_text` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `eav_entity`);
DELETE FROM `eav_entity_text` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_entity_varchar` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `eav_entity`);
DELETE FROM `eav_entity_varchar` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_form_element` WHERE `type_id` NOT IN (SELECT `type_id` FROM `eav_form_type`);
DELETE FROM `eav_form_element` WHERE `fieldset_id` NOT IN (SELECT `fieldset_id` FROM `eav_form_fieldset`);
DELETE FROM `eav_form_element` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `eav_form_fieldset` WHERE `type_id` NOT IN (SELECT `type_id` FROM `eav_form_type`);
DELETE FROM `eav_form_fieldset_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_form_fieldset_label` WHERE `fieldset_id` NOT IN (SELECT `fieldset_id` FROM `eav_form_fieldset`);
DELETE FROM `eav_form_type` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `eav_form_type_entity` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `eav_entity_type`);
DELETE FROM `eav_form_type_entity` WHERE `type_id` NOT IN (SELECT `type_id` FROM `eav_form_type`);
DELETE FROM `index_process_event` WHERE `event_id` NOT IN (SELECT `event_id` FROM `index_event`);
DELETE FROM `index_process_event` WHERE `process_id` NOT IN (SELECT `process_id` FROM `index_process`);
DELETE FROM `mage_admin_rule` WHERE `role_id` NOT IN (SELECT `role_id` FROM `mage_admin_role`);
DELETE FROM `mage_api2_acl_rule` WHERE `role_id` NOT IN (SELECT `entity_id` FROM `mage_api2_acl_role`);
DELETE FROM `mage_api2_acl_user` WHERE `admin_id` NOT IN (SELECT `user_id` FROM `mage_admin_user`);
DELETE FROM `mage_api2_acl_user` WHERE `role_id` NOT IN (SELECT `entity_id` FROM `mage_api2_acl_role`);
DELETE FROM `mage_api_rule` WHERE `role_id` NOT IN (SELECT `role_id` FROM `mage_api_role`);
DELETE FROM `mage_api_session` WHERE `user_id` NOT IN (SELECT `user_id` FROM `mage_api_user`);
DELETE FROM `mage_catalog_category_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_category_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_entity_datetime` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_category_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_category_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_entity_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_category_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_category_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_entity_int` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_category_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_category_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_entity_text` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_category_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_category_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_entity_varchar` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_category_flat_store_1` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_flat_store_1` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_category_product` WHERE `category_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_product` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_category_product_index` WHERE `category_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_catalog_category_product_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_category_product_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_compare_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_compare_item` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_catalog_compare_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_eav_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_bundle_option` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_bundle_option_value` WHERE `option_id` NOT IN (SELECT `option_id` FROM `mage_catalog_product_bundle_option`);
DELETE FROM `mage_catalog_product_bundle_price_index` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalog_product_bundle_price_index` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_bundle_price_index` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_bundle_selection` WHERE `option_id` NOT IN (SELECT `option_id` FROM `mage_catalog_product_bundle_option`);
DELETE FROM `mage_catalog_product_bundle_selection` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_bundle_selection_price` WHERE `selection_id` NOT IN (SELECT `selection_id` FROM `mage_catalog_product_bundle_selection`);
DELETE FROM `mage_catalog_product_bundle_selection_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_enabled_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_enabled_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_entity` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_catalog_product_entity` WHERE `attribute_set_id` NOT IN (SELECT `attribute_set_id` FROM `mage_eav_attribute_set`);
DELETE FROM `mage_catalog_product_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_datetime` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_entity_gallery` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_entity_gallery` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_gallery` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_entity_group_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_group_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalog_product_entity_group_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_int` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_entity_media_gallery` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_entity_media_gallery` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_media_gallery_value` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_entity_media_gallery_value` WHERE `value_id` NOT IN (SELECT `value_id` FROM `mage_catalog_product_entity_media_gallery`);
DELETE FROM `mage_catalog_product_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_text` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_entity_tier_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_tier_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalog_product_entity_tier_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_entity_varchar` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_flat_1` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_index_eav` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_index_eav` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_index_eav` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_index_eav_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_catalog_product_index_eav_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_index_eav_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_index_group_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_index_group_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalog_product_index_group_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_index_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalog_product_index_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_index_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_index_tier_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalog_product_index_tier_price` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_index_tier_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_index_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_link` WHERE `link_type_id` NOT IN (SELECT `link_type_id` FROM `mage_catalog_product_link_type`);
DELETE FROM `mage_catalog_product_link` WHERE `linked_product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_link` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_link_attribute` WHERE `link_type_id` NOT IN (SELECT `link_type_id` FROM `mage_catalog_product_link_type`);
DELETE FROM `mage_catalog_product_link_attribute_decimal` WHERE `product_link_attribute_id` NOT IN (SELECT `product_link_attribute_id` FROM `mage_catalog_product_link_attribute`);
DELETE FROM `mage_catalog_product_link_attribute_decimal` WHERE `link_id` NOT IN (SELECT `link_id` FROM `mage_catalog_product_link`);
DELETE FROM `mage_catalog_product_link_attribute_int` WHERE `product_link_attribute_id` NOT IN (SELECT `product_link_attribute_id` FROM `mage_catalog_product_link_attribute`);
DELETE FROM `mage_catalog_product_link_attribute_int` WHERE `link_id` NOT IN (SELECT `link_id` FROM `mage_catalog_product_link`);
DELETE FROM `mage_catalog_product_link_attribute_varchar` WHERE `product_link_attribute_id` NOT IN (SELECT `product_link_attribute_id` FROM `mage_catalog_product_link_attribute`);
DELETE FROM `mage_catalog_product_link_attribute_varchar` WHERE `link_id` NOT IN (SELECT `link_id` FROM `mage_catalog_product_link`);
DELETE FROM `mage_catalog_product_option` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_option_price` WHERE `option_id` NOT IN (SELECT `option_id` FROM `mage_catalog_product_option`);
DELETE FROM `mage_catalog_product_option_price` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_option_title` WHERE `option_id` NOT IN (SELECT `option_id` FROM `mage_catalog_product_option`);
DELETE FROM `mage_catalog_product_option_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_option_type_price` WHERE `option_type_id` NOT IN (SELECT `option_type_id` FROM `mage_catalog_product_option_type_value`);
DELETE FROM `mage_catalog_product_option_type_price` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_option_type_title` WHERE `option_type_id` NOT IN (SELECT `option_type_id` FROM `mage_catalog_product_option_type_value`);
DELETE FROM `mage_catalog_product_option_type_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_option_type_value` WHERE `option_id` NOT IN (SELECT `option_id` FROM `mage_catalog_product_option`);
DELETE FROM `mage_catalog_product_relation` WHERE `child_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_relation` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_super_attribute` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_super_attribute_label` WHERE `product_super_attribute_id` NOT IN (SELECT `product_super_attribute_id` FROM `mage_catalog_product_super_attribute`);
DELETE FROM `mage_catalog_product_super_attribute_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalog_product_super_attribute_pricing` WHERE `product_super_attribute_id` NOT IN (SELECT `product_super_attribute_id` FROM `mage_catalog_product_super_attribute`);
DELETE FROM `mage_catalog_product_super_attribute_pricing` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalog_product_super_link` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_super_link` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_website` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalog_product_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_cataloginventory_stock_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_cataloginventory_stock_item` WHERE `stock_id` NOT IN (SELECT `stock_id` FROM `mage_cataloginventory_stock`);
DELETE FROM `mage_cataloginventory_stock_status` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_cataloginventory_stock_status` WHERE `stock_id` NOT IN (SELECT `stock_id` FROM `mage_cataloginventory_stock`);
DELETE FROM `mage_cataloginventory_stock_status` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalogrule_customer_group` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalogrule_customer_group` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_catalogrule`);
DELETE FROM `mage_catalogrule_group_website` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalogrule_group_website` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_catalogrule`);
DELETE FROM `mage_catalogrule_group_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalogrule_product` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_catalogrule`);
DELETE FROM `mage_catalogrule_product` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalogrule_product` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalogrule_product` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalogrule_product_price` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_catalogrule_product_price` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalogrule_product_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalogrule_website` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_catalogrule`);
DELETE FROM `mage_catalogrule_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_catalogsearch_query` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_catalogsearch_result` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_catalogsearch_result` WHERE `query_id` NOT IN (SELECT `query_id` FROM `mage_catalogsearch_query`);
DELETE FROM `mage_checkout_agreement_store` WHERE `agreement_id` NOT IN (SELECT `agreement_id` FROM `mage_checkout_agreement`);
DELETE FROM `mage_checkout_agreement_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_cms_block_store` WHERE `block_id` NOT IN (SELECT `block_id` FROM `mage_cms_block`);
DELETE FROM `mage_cms_block_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_cms_page_store` WHERE `page_id` NOT IN (SELECT `page_id` FROM `mage_cms_page`);
DELETE FROM `mage_cms_page_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_core_email_queue_recipients` WHERE `message_id` NOT IN (SELECT `message_id` FROM `mage_core_email_queue`);
DELETE FROM `mage_core_layout_link` WHERE `layout_update_id` NOT IN (SELECT `layout_update_id` FROM `mage_core_layout_update`);
DELETE FROM `mage_core_layout_link` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_core_store` WHERE `group_id` NOT IN (SELECT `group_id` FROM `mage_core_store_group`);
DELETE FROM `mage_core_store` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_core_store_group` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_core_translate` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_core_url_rewrite` WHERE `category_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_category_entity`);
DELETE FROM `mage_core_url_rewrite` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_core_url_rewrite` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_core_variable_value` WHERE `variable_id` NOT IN (SELECT `variable_id` FROM `mage_core_variable`);
DELETE FROM `mage_core_variable_value` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_coupon_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_coupon_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_coupon_aggregated_updated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_customer_address_entity` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_customer_address_entity_datetime` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_address_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_address_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_address_entity`);
DELETE FROM `mage_customer_address_entity_decimal` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_address_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_address_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_address_entity`);
DELETE FROM `mage_customer_address_entity_int` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_address_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_address_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_address_entity`);
DELETE FROM `mage_customer_address_entity_text` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_address_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_address_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_address_entity`);
DELETE FROM `mage_customer_address_entity_varchar` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_address_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_address_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_address_entity`);
DELETE FROM `mage_customer_eav_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_eav_attribute_website` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_eav_attribute_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_customer_entity` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_customer_entity` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_customer_entity_datetime` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_entity_datetime` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_customer_entity_decimal` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_entity_decimal` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_customer_entity_int` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_entity_int` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_customer_entity_text` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_entity_text` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_customer_entity_varchar` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_customer_entity_varchar` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_customer_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_customer_form_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_dataflow_batch` WHERE `profile_id` NOT IN (SELECT `profile_id` FROM `mage_dataflow_profile`);
DELETE FROM `mage_dataflow_batch` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_dataflow_batch_export` WHERE `batch_id` NOT IN (SELECT `batch_id` FROM `mage_dataflow_batch`);
DELETE FROM `mage_dataflow_batch_import` WHERE `batch_id` NOT IN (SELECT `batch_id` FROM `mage_dataflow_batch`);
DELETE FROM `mage_dataflow_import_data` WHERE `session_id` NOT IN (SELECT `session_id` FROM `mage_dataflow_session`);
DELETE FROM `mage_dataflow_profile_history` WHERE `profile_id` NOT IN (SELECT `profile_id` FROM `mage_dataflow_profile`);
DELETE FROM `mage_design_change` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_directory_country_region_name` WHERE `region_id` NOT IN (SELECT `region_id` FROM `mage_directory_country_region`);
DELETE FROM `mage_downloadable_link` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_downloadable_link_price` WHERE `link_id` NOT IN (SELECT `link_id` FROM `mage_downloadable_link`);
DELETE FROM `mage_downloadable_link_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_downloadable_link_purchased` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_downloadable_link_purchased` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_downloadable_link_purchased_item` WHERE `order_item_id` NOT IN (SELECT `item_id` FROM `mage_sales_flat_order_item`);
DELETE FROM `mage_downloadable_link_purchased_item` WHERE `purchased_id` NOT IN (SELECT `purchased_id` FROM `mage_downloadable_link_purchased`);
DELETE FROM `mage_downloadable_link_title` WHERE `link_id` NOT IN (SELECT `link_id` FROM `mage_downloadable_link`);
DELETE FROM `mage_downloadable_link_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_downloadable_sample` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_downloadable_sample_title` WHERE `sample_id` NOT IN (SELECT `sample_id` FROM `mage_downloadable_sample`);
DELETE FROM `mage_downloadable_sample_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_attribute` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_attribute_group` WHERE `attribute_set_id` NOT IN (SELECT `attribute_set_id` FROM `mage_eav_attribute_set`);
DELETE FROM `mage_eav_attribute_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_attribute_label` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_eav_attribute_option` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_eav_attribute_option_value` WHERE `option_id` NOT IN (SELECT `option_id` FROM `mage_eav_attribute_option`);
DELETE FROM `mage_eav_attribute_option_value` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_attribute_set` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_entity` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity_attribute` WHERE `attribute_group_id` NOT IN (SELECT `attribute_group_id` FROM `mage_eav_attribute_group`);
DELETE FROM `mage_eav_entity_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_eav_entity_datetime` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity_datetime` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_eav_entity`);
DELETE FROM `mage_eav_entity_datetime` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_entity_decimal` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity_decimal` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_eav_entity`);
DELETE FROM `mage_eav_entity_decimal` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_entity_int` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity_int` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_eav_entity`);
DELETE FROM `mage_eav_entity_int` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_entity_store` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_entity_text` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity_text` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_eav_entity`);
DELETE FROM `mage_eav_entity_text` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_entity_varchar` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_entity_varchar` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_eav_entity`);
DELETE FROM `mage_eav_entity_varchar` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_form_element` WHERE `type_id` NOT IN (SELECT `type_id` FROM `mage_eav_form_type`);
DELETE FROM `mage_eav_form_element` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_eav_form_element` WHERE `fieldset_id` NOT IN (SELECT `fieldset_id` FROM `mage_eav_form_fieldset`);
DELETE FROM `mage_eav_form_fieldset` WHERE `type_id` NOT IN (SELECT `type_id` FROM `mage_eav_form_type`);
DELETE FROM `mage_eav_form_fieldset_label` WHERE `fieldset_id` NOT IN (SELECT `fieldset_id` FROM `mage_eav_form_fieldset`);
DELETE FROM `mage_eav_form_fieldset_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_form_type` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_eav_form_type_entity` WHERE `entity_type_id` NOT IN (SELECT `entity_type_id` FROM `mage_eav_entity_type`);
DELETE FROM `mage_eav_form_type_entity` WHERE `type_id` NOT IN (SELECT `type_id` FROM `mage_eav_form_type`);
DELETE FROM `mage_index_process_event` WHERE `process_id` NOT IN (SELECT `process_id` FROM `mage_index_process`);
DELETE FROM `mage_index_process_event` WHERE `event_id` NOT IN (SELECT `event_id` FROM `mage_index_event`);
DELETE FROM `mage_newsletter_problem` WHERE `subscriber_id` NOT IN (SELECT `subscriber_id` FROM `mage_newsletter_subscriber`);
DELETE FROM `mage_newsletter_problem` WHERE `queue_id` NOT IN (SELECT `queue_id` FROM `mage_newsletter_queue`);
DELETE FROM `mage_newsletter_queue` WHERE `template_id` NOT IN (SELECT `template_id` FROM `mage_newsletter_template`);
DELETE FROM `mage_newsletter_queue_link` WHERE `subscriber_id` NOT IN (SELECT `subscriber_id` FROM `mage_newsletter_subscriber`);
DELETE FROM `mage_newsletter_queue_link` WHERE `queue_id` NOT IN (SELECT `queue_id` FROM `mage_newsletter_queue`);
DELETE FROM `mage_newsletter_queue_store_link` WHERE `queue_id` NOT IN (SELECT `queue_id` FROM `mage_newsletter_queue`);
DELETE FROM `mage_newsletter_queue_store_link` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_newsletter_subscriber` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_oauth_token` WHERE `admin_id` NOT IN (SELECT `user_id` FROM `mage_admin_user`);
DELETE FROM `mage_oauth_token` WHERE `consumer_id` NOT IN (SELECT `entity_id` FROM `mage_oauth_consumer`);
DELETE FROM `mage_oauth_token` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_paypal_cert` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_paypal_settlement_report_row` WHERE `report_id` NOT IN (SELECT `report_id` FROM `mage_paypal_settlement_report`);
DELETE FROM `mage_persistent_session` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_persistent_session` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_poll` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_poll_answer` WHERE `poll_id` NOT IN (SELECT `poll_id` FROM `mage_poll`);
DELETE FROM `mage_poll_store` WHERE `poll_id` NOT IN (SELECT `poll_id` FROM `mage_poll`);
DELETE FROM `mage_poll_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_poll_vote` WHERE `poll_answer_id` NOT IN (SELECT `answer_id` FROM `mage_poll_answer`);
DELETE FROM `mage_product_alert_price` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_product_alert_price` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_product_alert_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_product_alert_stock` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_product_alert_stock` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_product_alert_stock` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_rating` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_rating_entity`);
DELETE FROM `mage_rating_option` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `mage_rating`);
DELETE FROM `mage_rating_option_vote` WHERE `review_id` NOT IN (SELECT `review_id` FROM `mage_review`);
DELETE FROM `mage_rating_option_vote` WHERE `option_id` NOT IN (SELECT `option_id` FROM `mage_rating_option`);
DELETE FROM `mage_rating_option_vote_aggregated` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `mage_rating`);
DELETE FROM `mage_rating_option_vote_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_rating_store` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `mage_rating`);
DELETE FROM `mage_rating_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_rating_title` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `mage_rating`);
DELETE FROM `mage_rating_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_report_compared_product_index` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_report_compared_product_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_report_compared_product_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_report_event` WHERE `event_type_id` NOT IN (SELECT `event_type_id` FROM `mage_report_event_types`);
DELETE FROM `mage_report_event` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_report_viewed_product_aggregated_daily` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_report_viewed_product_aggregated_daily` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_report_viewed_product_aggregated_monthly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_report_viewed_product_aggregated_monthly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_report_viewed_product_aggregated_yearly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_report_viewed_product_aggregated_yearly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_report_viewed_product_index` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_report_viewed_product_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_report_viewed_product_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_review` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_review_entity`);
DELETE FROM `mage_review` WHERE `status_id` NOT IN (SELECT `status_id` FROM `mage_review_status`);
DELETE FROM `mage_review_detail` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_review_detail` WHERE `review_id` NOT IN (SELECT `review_id` FROM `mage_review`);
DELETE FROM `mage_review_detail` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_review_entity_summary` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_review_store` WHERE `review_id` NOT IN (SELECT `review_id` FROM `mage_review`);
DELETE FROM `mage_review_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_bestsellers_aggregated_daily` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_sales_bestsellers_aggregated_daily` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_bestsellers_aggregated_monthly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_bestsellers_aggregated_monthly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_sales_bestsellers_aggregated_yearly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_sales_bestsellers_aggregated_yearly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_billing_agreement` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_sales_billing_agreement` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_billing_agreement_order` WHERE `agreement_id` NOT IN (SELECT `agreement_id` FROM `mage_sales_billing_agreement`);
DELETE FROM `mage_sales_billing_agreement_order` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_creditmemo` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_creditmemo` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_creditmemo_comment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_creditmemo`);
DELETE FROM `mage_sales_flat_creditmemo_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_creditmemo`);
DELETE FROM `mage_sales_flat_creditmemo_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_creditmemo_item` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_creditmemo`);
DELETE FROM `mage_sales_flat_invoice` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_invoice` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_invoice_comment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_invoice`);
DELETE FROM `mage_sales_flat_invoice_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_invoice_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_invoice`);
DELETE FROM `mage_sales_flat_invoice_item` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_invoice`);
DELETE FROM `mage_sales_flat_order` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_sales_flat_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_order_address` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_order_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_order_grid` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_sales_flat_order_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_order_item` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_order_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_order_payment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_order_status_history` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_quote` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_quote_address` WHERE `quote_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_quote`);
DELETE FROM `mage_sales_flat_quote_address_item` WHERE `quote_address_id` NOT IN (SELECT `address_id` FROM `mage_sales_flat_quote_address`);
DELETE FROM `mage_sales_flat_quote_item` WHERE `quote_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_quote`);
DELETE FROM `mage_sales_flat_quote_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_sales_flat_quote_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_quote_item_option` WHERE `item_id` NOT IN (SELECT `item_id` FROM `mage_sales_flat_quote_item`);
DELETE FROM `mage_sales_flat_quote_payment` WHERE `quote_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_quote`);
DELETE FROM `mage_sales_flat_quote_shipping_rate` WHERE `address_id` NOT IN (SELECT `address_id` FROM `mage_sales_flat_quote_address`);
DELETE FROM `mage_sales_flat_shipment` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_flat_shipment` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_shipment_comment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_shipment`);
DELETE FROM `mage_sales_flat_shipment_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_shipment`);
DELETE FROM `mage_sales_flat_shipment_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_flat_shipment_item` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_shipment`);
DELETE FROM `mage_sales_flat_shipment_track` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_shipment`);
DELETE FROM `mage_sales_invoiced_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_invoiced_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_order_aggregated_created` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_order_aggregated_updated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_order_status_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_order_status_label` WHERE `status` NOT IN (SELECT `status` FROM `mage_sales_order_status`);
DELETE FROM `mage_sales_order_status_state` WHERE `status` NOT IN (SELECT `status` FROM `mage_sales_order_status`);
DELETE FROM `mage_sales_order_tax_item` WHERE `item_id` NOT IN (SELECT `item_id` FROM `mage_sales_flat_order_item`);
DELETE FROM `mage_sales_order_tax_item` WHERE `tax_id` NOT IN (SELECT `tax_id` FROM `mage_sales_order_tax`);
DELETE FROM `mage_sales_payment_transaction` WHERE `payment_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order_payment`);
DELETE FROM `mage_sales_payment_transaction` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_recurring_profile` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_recurring_profile` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_sales_recurring_profile_order` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `mage_sales_flat_order`);
DELETE FROM `mage_sales_recurring_profile_order` WHERE `profile_id` NOT IN (SELECT `profile_id` FROM `mage_sales_recurring_profile`);
DELETE FROM `mage_sales_refunded_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_refunded_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_shipping_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_sales_shipping_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_salesrule_coupon` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_salesrule`);
DELETE FROM `mage_salesrule_coupon_usage` WHERE `coupon_id` NOT IN (SELECT `coupon_id` FROM `mage_salesrule_coupon`);
DELETE FROM `mage_salesrule_coupon_usage` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_salesrule_customer` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_salesrule_customer` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_salesrule`);
DELETE FROM `mage_salesrule_customer_group` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_salesrule_customer_group` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_salesrule`);
DELETE FROM `mage_salesrule_label` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_salesrule`);
DELETE FROM `mage_salesrule_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_salesrule_product_attribute` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_salesrule_product_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_salesrule_product_attribute` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_salesrule`);
DELETE FROM `mage_salesrule_product_attribute` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_salesrule_website` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `mage_salesrule`);
DELETE FROM `mage_salesrule_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_tag` WHERE `first_customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_tag` WHERE `first_store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_tag_properties` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_tag_properties` WHERE `tag_id` NOT IN (SELECT `tag_id` FROM `mage_tag`);
DELETE FROM `mage_tag_relation` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_tag_relation` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_tag_relation` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_tag_relation` WHERE `tag_id` NOT IN (SELECT `tag_id` FROM `mage_tag`);
DELETE FROM `mage_tag_summary` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_tag_summary` WHERE `tag_id` NOT IN (SELECT `tag_id` FROM `mage_tag`);
DELETE FROM `mage_tax_calculation` WHERE `tax_calculation_rate_id` NOT IN (SELECT `tax_calculation_rate_id` FROM `mage_tax_calculation_rate`);
DELETE FROM `mage_tax_calculation` WHERE `tax_calculation_rule_id` NOT IN (SELECT `tax_calculation_rule_id` FROM `mage_tax_calculation_rule`);
DELETE FROM `mage_tax_calculation` WHERE `customer_tax_class_id` NOT IN (SELECT `class_id` FROM `mage_tax_class`);
DELETE FROM `mage_tax_calculation` WHERE `product_tax_class_id` NOT IN (SELECT `class_id` FROM `mage_tax_class`);
DELETE FROM `mage_tax_calculation_rate_title` WHERE `tax_calculation_rate_id` NOT IN (SELECT `tax_calculation_rate_id` FROM `mage_tax_calculation_rate`);
DELETE FROM `mage_tax_calculation_rate_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_tax_order_aggregated_created` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_tax_order_aggregated_updated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_weee_discount` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `mage_customer_group`);
DELETE FROM `mage_weee_discount` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_weee_discount` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_weee_tax` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `mage_eav_attribute`);
DELETE FROM `mage_weee_tax` WHERE `country` NOT IN (SELECT `country_id` FROM `mage_directory_country`);
DELETE FROM `mage_weee_tax` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_weee_tax` WHERE `website_id` NOT IN (SELECT `website_id` FROM `mage_core_website`);
DELETE FROM `mage_widget_instance_page` WHERE `instance_id` NOT IN (SELECT `instance_id` FROM `mage_widget_instance`);
DELETE FROM `mage_widget_instance_page_layout` WHERE `layout_update_id` NOT IN (SELECT `layout_update_id` FROM `mage_core_layout_update`);
DELETE FROM `mage_widget_instance_page_layout` WHERE `page_id` NOT IN (SELECT `page_id` FROM `mage_widget_instance_page`);
DELETE FROM `mage_wishlist` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `mage_customer_entity`);
DELETE FROM `mage_wishlist_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `mage_catalog_product_entity`);
DELETE FROM `mage_wishlist_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `mage_core_store`);
DELETE FROM `mage_wishlist_item` WHERE `wishlist_id` NOT IN (SELECT `wishlist_id` FROM `mage_wishlist`);
DELETE FROM `mage_wishlist_item_option` WHERE `wishlist_item_id` NOT IN (SELECT `wishlist_item_id` FROM `mage_wishlist_item`);
DELETE FROM `newsletter_problem` WHERE `subscriber_id` NOT IN (SELECT `subscriber_id` FROM `newsletter_subscriber`);
DELETE FROM `newsletter_problem` WHERE `queue_id` NOT IN (SELECT `queue_id` FROM `newsletter_queue`);
DELETE FROM `newsletter_queue` WHERE `template_id` NOT IN (SELECT `template_id` FROM `newsletter_template`);
DELETE FROM `newsletter_queue_link` WHERE `queue_id` NOT IN (SELECT `queue_id` FROM `newsletter_queue`);
DELETE FROM `newsletter_queue_link` WHERE `subscriber_id` NOT IN (SELECT `subscriber_id` FROM `newsletter_subscriber`);
DELETE FROM `newsletter_queue_store_link` WHERE `queue_id` NOT IN (SELECT `queue_id` FROM `newsletter_queue`);
DELETE FROM `newsletter_queue_store_link` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `newsletter_subscriber` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `oauth_token` WHERE `admin_id` NOT IN (SELECT `user_id` FROM `admin_user`);
DELETE FROM `oauth_token` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `oauth_token` WHERE `consumer_id` NOT IN (SELECT `entity_id` FROM `oauth_consumer`);
DELETE FROM `paypal_cert` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `paypal_settlement_report_row` WHERE `report_id` NOT IN (SELECT `report_id` FROM `paypal_settlement_report`);
DELETE FROM `persistent_session` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `persistent_session` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `poll` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `poll_answer` WHERE `poll_id` NOT IN (SELECT `poll_id` FROM `poll`);
DELETE FROM `poll_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `poll_store` WHERE `poll_id` NOT IN (SELECT `poll_id` FROM `poll`);
DELETE FROM `poll_vote` WHERE `poll_answer_id` NOT IN (SELECT `answer_id` FROM `poll_answer`);
DELETE FROM `product_alert_price` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `product_alert_price` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `product_alert_price` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `product_alert_stock` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `product_alert_stock` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `product_alert_stock` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `rating` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `rating_entity`);
DELETE FROM `rating_option` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `rating`);
DELETE FROM `rating_option_vote` WHERE `option_id` NOT IN (SELECT `option_id` FROM `rating_option`);
DELETE FROM `rating_option_vote` WHERE `review_id` NOT IN (SELECT `review_id` FROM `review`);
DELETE FROM `rating_option_vote_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `rating_option_vote_aggregated` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `rating`);
DELETE FROM `rating_store` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `rating`);
DELETE FROM `rating_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `rating_title` WHERE `rating_id` NOT IN (SELECT `rating_id` FROM `rating`);
DELETE FROM `rating_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `report_compared_product_index` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `report_compared_product_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `report_compared_product_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `report_event` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `report_event` WHERE `event_type_id` NOT IN (SELECT `event_type_id` FROM `report_event_types`);
DELETE FROM `report_viewed_product_aggregated_daily` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `report_viewed_product_aggregated_daily` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `report_viewed_product_aggregated_monthly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `report_viewed_product_aggregated_monthly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `report_viewed_product_aggregated_yearly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `report_viewed_product_aggregated_yearly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `report_viewed_product_index` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `report_viewed_product_index` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `report_viewed_product_index` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `review` WHERE `status_id` NOT IN (SELECT `status_id` FROM `review_status`);
DELETE FROM `review` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `review_entity`);
DELETE FROM `review_detail` WHERE `review_id` NOT IN (SELECT `review_id` FROM `review`);
DELETE FROM `review_detail` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `review_detail` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `review_entity_summary` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `review_store` WHERE `review_id` NOT IN (SELECT `review_id` FROM `review`);
DELETE FROM `review_store` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_bestsellers_aggregated_daily` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_bestsellers_aggregated_daily` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `sales_bestsellers_aggregated_monthly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `sales_bestsellers_aggregated_monthly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_bestsellers_aggregated_yearly` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `sales_bestsellers_aggregated_yearly` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_billing_agreement` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `sales_billing_agreement` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_billing_agreement_order` WHERE `agreement_id` NOT IN (SELECT `agreement_id` FROM `sales_billing_agreement`);
DELETE FROM `sales_billing_agreement_order` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_creditmemo` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_creditmemo` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_creditmemo_comment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_creditmemo`);
DELETE FROM `sales_flat_creditmemo_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `sales_flat_creditmemo`);
DELETE FROM `sales_flat_creditmemo_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_creditmemo_item` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_creditmemo`);
DELETE FROM `sales_flat_invoice` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_invoice` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_invoice_comment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_invoice`);
DELETE FROM `sales_flat_invoice_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `sales_flat_invoice`);
DELETE FROM `sales_flat_invoice_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_invoice_item` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_invoice`);
DELETE FROM `sales_flat_order` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `sales_flat_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_order_address` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_order_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_order_grid` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `sales_flat_order_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_order_item` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_order_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_order_payment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_order_status_history` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_quote` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_quote_address` WHERE `quote_id` NOT IN (SELECT `entity_id` FROM `sales_flat_quote`);
DELETE FROM `sales_flat_quote_address_item` WHERE `quote_item_id` NOT IN (SELECT `item_id` FROM `sales_flat_quote_item`);
DELETE FROM `sales_flat_quote_address_item` WHERE `quote_address_id` NOT IN (SELECT `address_id` FROM `sales_flat_quote_address`);
DELETE FROM `sales_flat_quote_item` WHERE `quote_id` NOT IN (SELECT `entity_id` FROM `sales_flat_quote`);
DELETE FROM `sales_flat_quote_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_quote_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `sales_flat_quote_item_option` WHERE `item_id` NOT IN (SELECT `item_id` FROM `sales_flat_quote_item`);
DELETE FROM `sales_flat_quote_payment` WHERE `quote_id` NOT IN (SELECT `entity_id` FROM `sales_flat_quote`);
DELETE FROM `sales_flat_quote_shipping_rate` WHERE `address_id` NOT IN (SELECT `address_id` FROM `sales_flat_quote_address`);
DELETE FROM `sales_flat_shipment` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_shipment` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_flat_shipment_comment` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_shipment`);
DELETE FROM `sales_flat_shipment_grid` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_flat_shipment_grid` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `sales_flat_shipment`);
DELETE FROM `sales_flat_shipment_item` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_shipment`);
DELETE FROM `sales_flat_shipment_track` WHERE `parent_id` NOT IN (SELECT `entity_id` FROM `sales_flat_shipment`);
DELETE FROM `sales_invoiced_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_invoiced_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_order_aggregated_created` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_order_aggregated_updated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_order_status_label` WHERE `status` NOT IN (SELECT `status` FROM `sales_order_status`);
DELETE FROM `sales_order_status_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_order_status_state` WHERE `status` NOT IN (SELECT `status` FROM `sales_order_status`);
DELETE FROM `sales_order_tax_item` WHERE `item_id` NOT IN (SELECT `item_id` FROM `sales_flat_order_item`);
DELETE FROM `sales_order_tax_item` WHERE `tax_id` NOT IN (SELECT `tax_id` FROM `sales_order_tax`);
DELETE FROM `sales_payment_transaction` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_payment_transaction` WHERE `payment_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order_payment`);
DELETE FROM `sales_recurring_profile` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `sales_recurring_profile` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_recurring_profile_order` WHERE `profile_id` NOT IN (SELECT `profile_id` FROM `sales_recurring_profile`);
DELETE FROM `sales_recurring_profile_order` WHERE `order_id` NOT IN (SELECT `entity_id` FROM `sales_flat_order`);
DELETE FROM `sales_refunded_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_refunded_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_shipping_aggregated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `sales_shipping_aggregated_order` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `salesrule_coupon` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `salesrule`);
DELETE FROM `salesrule_coupon_usage` WHERE `coupon_id` NOT IN (SELECT `coupon_id` FROM `salesrule_coupon`);
DELETE FROM `salesrule_coupon_usage` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `salesrule_customer` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `salesrule`);
DELETE FROM `salesrule_customer` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `salesrule_customer_group` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `salesrule_customer_group` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `salesrule`);
DELETE FROM `salesrule_label` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `salesrule_label` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `salesrule`);
DELETE FROM `salesrule_product_attribute` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `salesrule_product_attribute` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `salesrule_product_attribute` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `salesrule`);
DELETE FROM `salesrule_product_attribute` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `salesrule_website` WHERE `rule_id` NOT IN (SELECT `rule_id` FROM `salesrule`);
DELETE FROM `salesrule_website` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `sitemap` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `tag` WHERE `first_store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `tag` WHERE `first_customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `tag_properties` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `tag_properties` WHERE `tag_id` NOT IN (SELECT `tag_id` FROM `tag`);
DELETE FROM `tag_relation` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `tag_relation` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `tag_relation` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `tag_relation` WHERE `tag_id` NOT IN (SELECT `tag_id` FROM `tag`);
DELETE FROM `tag_summary` WHERE `tag_id` NOT IN (SELECT `tag_id` FROM `tag`);
DELETE FROM `tag_summary` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `tax_calculation` WHERE `customer_tax_class_id` NOT IN (SELECT `class_id` FROM `tax_class`);
DELETE FROM `tax_calculation` WHERE `product_tax_class_id` NOT IN (SELECT `class_id` FROM `tax_class`);
DELETE FROM `tax_calculation` WHERE `tax_calculation_rule_id` NOT IN (SELECT `tax_calculation_rule_id` FROM `tax_calculation_rule`);
DELETE FROM `tax_calculation` WHERE `tax_calculation_rate_id` NOT IN (SELECT `tax_calculation_rate_id` FROM `tax_calculation_rate`);
DELETE FROM `tax_calculation_rate_title` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `tax_calculation_rate_title` WHERE `tax_calculation_rate_id` NOT IN (SELECT `tax_calculation_rate_id` FROM `tax_calculation_rate`);
DELETE FROM `tax_order_aggregated_created` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `tax_order_aggregated_updated` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `weee_discount` WHERE `customer_group_id` NOT IN (SELECT `customer_group_id` FROM `customer_group`);
DELETE FROM `weee_discount` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `weee_discount` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `weee_tax` WHERE `attribute_id` NOT IN (SELECT `attribute_id` FROM `eav_attribute`);
DELETE FROM `weee_tax` WHERE `website_id` NOT IN (SELECT `website_id` FROM `core_website`);
DELETE FROM `weee_tax` WHERE `entity_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `weee_tax` WHERE `country` NOT IN (SELECT `country_id` FROM `directory_country`);
DELETE FROM `widget_instance_page` WHERE `instance_id` NOT IN (SELECT `instance_id` FROM `widget_instance`);
DELETE FROM `widget_instance_page_layout` WHERE `page_id` NOT IN (SELECT `page_id` FROM `widget_instance_page`);
DELETE FROM `widget_instance_page_layout` WHERE `layout_update_id` NOT IN (SELECT `layout_update_id` FROM `core_layout_update`);
DELETE FROM `wishlist` WHERE `customer_id` NOT IN (SELECT `entity_id` FROM `customer_entity`);
DELETE FROM `wishlist_item` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `wishlist_item` WHERE `product_id` NOT IN (SELECT `entity_id` FROM `catalog_product_entity`);
DELETE FROM `wishlist_item` WHERE `wishlist_id` NOT IN (SELECT `wishlist_id` FROM `wishlist`);
DELETE FROM `wishlist_item_option` WHERE `wishlist_item_id` NOT IN (SELECT `wishlist_item_id` FROM `wishlist_item`);
DELETE FROM `xmlconnect_application` WHERE `store_id` NOT IN (SELECT `store_id` FROM `core_store`);
DELETE FROM `xmlconnect_config_data` WHERE `application_id` NOT IN (SELECT `application_id` FROM `xmlconnect_application`);
DELETE FROM `xmlconnect_history` WHERE `application_id` NOT IN (SELECT `application_id` FROM `xmlconnect_application`);
DELETE FROM `xmlconnect_notification_template` WHERE `application_id` NOT IN (SELECT `application_id` FROM `xmlconnect_application`);
DELETE FROM `xmlconnect_queue` WHERE `template_id` NOT IN (SELECT `template_id` FROM `xmlconnect_notification_template`);
I hope this helps to cleanup your database and to get your Magento migration over the line.