#http://stackoverflow.com/questions/29673696/magento-category-products-reindex-error/29676254#29676254
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_product_website` WHERE product_id not in(select entity_id from catalog_product_entity);
delete from `catalog_product_index_eav_idx` WHERE entity_id not in(select entity_id from catalog_product_entity);
delete from `catalog_product_index_eav` WHERE entity_id not in(select entity_id from catalog_product_entity);
delete from `catalog_product_link` WHERE product_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 `sales_flat_quote_shipping_rate` WHERE `address_id` not in(select `address_id` from `sales_flat_quote_address`);
# Determine incorrect product associations
SELECT * FROM `catalog_category_product` WHERE
product_id not in (select entity_id from catalog_product_entity);
# Determine incorrect categories
SELECT * FROM `catalog_category_product` WHERE
category_id not in (select entity_id from catalog_category_entity);
# Delete incorrect product associations
DELETE FROM `catalog_category_product` WHERE
product_id not in (select entity_id from catalog_product_entity);
# Delete incorrect categories
DELETE FROM `catalog_category_product` WHERE
category_id not in (select entity_id from catalog_category_entity);