You can query the products_to_categories table for all the categories in which a product is located.