How to request a comma separated string?

TABLE_A

column name: list_id record 1: 1,2,5,6,8 record 2: 1,3,2 record 3: 6,7,2 record 4: 9,8,0 

TABLE_B

 id ='2'; 

How to select records having id='2' in a comma separated line? In the above example, it should return records 1,2 and 3.

Request (how to change this request, please?):

 SELECT * FROM Table_a,Table_b WHERE Table_b.id = Table_a.list_id; 
+7
php mysql
source share
2 answers

use the find_in_set function, but it is not optimized, since you have to normalize your data.

 SELECT * FROM Table_a AS a JOIN Table_b AS b ON FIND_IN_SET(b.id,a.list_id) 
+3
source share

This should work for you.

 SELECT * FROM Table_a,Table_b WHERE Table_b.id = Table_a.list_id and concat(',',Table_a.list_id,',') like '%,2,%' 
0
source share

All Articles