2
SELECT `e`.`id`, `e`.`title`, `e`.`description`, `e`.`event_time`,(SELECT GROUP_CONCAT( name SEPARATOR " | " ) 
FROM `ar_products` 
WHERE id IN **(e.products)** AS products FROM events e;

I have list of comma separated product id's in events table with column name products. If I use the values 54,33,23.. it is showing correct values like list of products [product1 | product2 | ..].

Its not working when I use column name directly in IN CLAUSE.

Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
maxatmin.com
  • 51
  • 1
  • 4
  • See [Is storing a delimited list in a database column really that bad?](http://stackoverflow.com/a/3653574) – eggyal Jul 10 '13 at 12:41

1 Answers1

20

It sound like you are looking for FIND_IN_SET http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set. Change the WHERE clause to:

WHERE FIND_IN_SET(id, e.products) AS products FROM events e;
keithhatfield
  • 3,273
  • 1
  • 17
  • 24