SELECT
c.entity_id AS category_id,
cev.value AS category_name,
p.entity_id AS product_id,
p.sku AS product_sku,
cp.position AS product_position
FROM
catalog_category_product cp
INNER JOIN
catalog_category_entity c ON cp.category_id = c.entity_id
INNER JOIN
catalog_product_entity p ON cp.product_id = p.entity_id
LEFT JOIN
catalog_category_entity_varchar cev ON c.entity_id = cev.entity_id
AND cev.attribute_id = (
SELECT attribute_id FROM eav_attribute
WHERE attribute_code = 'name' AND entity_type_id = (
SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category'
)
)
ORDER BY
c.entity_id ASC, cp.position ASC;