I have 2 tables:
1. products
- product_id
- title
2. product_categories
- product_id
- category_id
Each product can have more than one category. I store this information in the product_categories table. I want to be able to SELECT all the category_ids when I select a product in 1 query. How can I do this? I have the following so far, but it will only select 1 category id:
SELECT
p.*,
(SELECT
category_id
FROM
product_categories
WHERE product_id = p.product_id) as category_ids
FROM
products AS p