2

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 .

2
  • 4
    Isn't it select * from table where Tid IN (1,10)? Commented May 26, 2016 at 11:32
  • Really thank you friends Commented May 26, 2016 at 11:35

1 Answer 1

6

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you . It is working . I don't have reputation to vote you now . But i will make this as selected answer .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.