SELECT 
	1,
	cpf.entity_id AS products_id,
	ccf.entity_id AS categories_id,
	cpf.small_image categories_image,
	ccf.parent_id AS parent_id,
	0 sort_order,
	ccf.name AS categories_name   

FROM 
	catalog_category_product ccp,
	catalog_product_flat_<@PREFIX> cpf,
	catalog_category_flat_store_<@PREFIX> ccf

WHERE
	ccp.product_id = cpf.entity_id AND 
	ccp.category_id = ccf.entity_id