0

I have tried left join, inner join, join and nested select queries but it is always giving me one result set even though table A has multiple comma separated values.

The simplest solution which i could figure was query twice which gives me the result, if i query the product_ids from table A and then based on the result query table B. Where product_ids has multiple comma separated values.

How could i make a single query like this one?

SELECT * 
FROM `sys_products` 
WHERE id IN ( 
    SELECT sys_cart.product_ids 
    FROM `sys_cart` 
    WHERE userid = 2 
)

Why won't this query work? The FIND_IN_SET also does not work.

  • @Barmar if it would have been correct the user would have accepted it. You can't mark questions duplicate only if you have answered them would have appreciated the help. Thanks. – Abhijeet Chakravorty Feb 20 '17 at 21:03
  • Did you try that solution? Doesn't it work? You should really normalize your data, though. – Barmar Feb 20 '17 at 21:10
  • @Barmar it does not work. The case is entirely something else i do not wish to concat any of the data i just wish to display the list of the products which are saved as comma separated strings in another table. – Abhijeet Chakravorty Feb 21 '17 at 10:03
  • So i figured the solution which is not given by @Barmar in his solution. The query is something like this SELECT * FROM sys_products INNER JOIN sys_cart ON FIND_IN_SET(sys_products.id, sys_cart.product_ids) WHERE sys_cart.userid=2. – Abhijeet Chakravorty Feb 21 '17 at 10:13
  • Isn't that the same as my answer in the linked question? The relevant part is using `ON FIND_IN_SET(...)` – Barmar Feb 22 '17 at 18:56
  • Here's a simpler duplicate: http://stackoverflow.com/questions/16208565/search-with-comma-separated-value-mysql/16210672#16210672 I'll use this one in the future for questions like this. – Barmar Feb 22 '17 at 19:01

0 Answers0