John John - 4 months ago 7x
MySQL Question

Like % with many values in sql

How to write the like% query with too many values in sql ?

For example ,please see the table structure

Id Tid name
1 1 test
2 3 ram
3 10 felix

select * from table where Tid Like % 1,10 %

Also i am putting this value in a form , so post variable value like
so i am going to will implement this like

select * from table where Tid Like % $_POST['tid'] %

Thank you .


MySQL offers find_in_set():

where find_in_set(Tid, '1,10') > 0

Note that this will not use an index. You can use implode() in php to use in instead, resulting in:

where tid in (1, 10)