Rev Rev - 2 months ago 5
PHP Question

how to fetch multiple columns containing multiple values using a specific value from single table in PHP/MYSQL

I want to fetch multiple columns containing multiple values using a specific value from single table in PHP/MYSQL.

My table structure is like,

id | Name | s_id |
-----------------------------
1 | aaa | 3 10 13 |
2 | bbb | 1 2 5 8 16 23 |
3 | ccc | 1 3 11 19 25 |
4 | ddd | 7 15 19 25 |
5 | eee | 5 13 16 21 |


My query is,

"SELECT Name FROM table where s_id like '%1%'"


I should get the output as,

bbb
ccc


but i'm getting all the names whose 'id' has
'1'
in its value,
i.e. 1, 11, 19, 16, etc.
What should i change in my code and table structure? do i need to use any delimiter? am coding it in php.
pls help me out.
Thanks in advance.

Answer

Try this REGEXP '[[:<:]]1[[:>:]]'

"SELECT Name FROM table where s_id REGEXP '[[:<:]]1[[:>:]]'"