John John - 2 years ago 157
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 .

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download