0

I have an issue to get concatenated text from below two tables(product_to_category & category_description)

enter image description here

product_to_category

I need mysql query to get output as "Electronics,Electronics Component Connectors,Electronics Accessories" from category_description table's name column.That query will compare category_id in these tables with where condition as product_id = 276.

I tried this query,but it returns empty result -

 SELECT GROUP_CONCAT(description SEPARATOR ',') 
  FROM `ocrk_category_description` 
 WHERE `category_id` IN (SELECT GROUP_CONCAT(category_id SEPARATOR ',') as `category_id` 
                           FROM `ocrk_product_to_category` 
                          WHERE `product_id` = 276 
                        )

Any ideas? i can provide you more information if need.

0

I'm not 100% sure if I understand the question correct, but i'll try some solution!:

    SELECT a.product_id, group_concat(distinct b.name)
    FROM product_to_category a
    JOIN category_description b
    ON a.category_id = b.category_id
    GROUP BY a.product_id;

I hope this is what you were looking for...

Cheers, Olaf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.