To get the parent category ID of a product in MySQL, you can use the following query:
FROM catalog_category_product AS cp
INNER JOIN catalog_category AS c ON cp.category_id = c.entity_id
WHERE cp.product_id = [PRODUCT_ID]
AND c.parent_id != 0
ORDER BY c.level DESC
Replace [PRODUCT_ID] with the actual ID of your product. This query will return the ID of the top-level parent category of the product, in this case, 5 for the "Books" category.
Note that this assumes that your category tree has only one level of parent categories. If you have a more complex category structure with multiple levels of parent categories, you may need to modify the query accordingly.