SELECT c.id AS id, c.name AS name, \
GROUP_CONCAT(DISTINCT cp.product_id) AS product_id, \
GROUP_CONCAT(DISTINCT cp.category_id) AS category_id \
FROM categories AS c \
INNER JOIN categories_products AS cp ON c.id = cp.category_id \
GROUP BY c.id \