John
John

Reputation: 29

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 $_POST['tid']=1,10 so i am going to will implement this like

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

Thank you .

Upvotes: 2

Views: 83

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270443

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)

Upvotes: 6

Related Questions