Multiple conditions in LIKE operator

209 views Asked by At

i am getting multiple values in this $languages like(php,Ruby) i want spilt that and how to check that split values in this query

SELECT * FROM software_capability where languages LIKE '%$languages%'
4

There are 4 answers

0
m-farhan On BEST ANSWER

Try with this.

 SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%')

This is syntax. Exploded your $language and put each item in '%$item%'

0
Chanon On
SELECT * FROM software_capability where CONCAT('%',languages,'%') LIKE '$languages';

assuming that $languages is 'php,Ruby'

0
sarwar026 On

If $languages is comma (,) separated values, then you can try with IN command of mysql

SELECT * FROM software_capability where languages IN ($languages)
1
Akg On

As in other languages Mysql also supports regexp for pattern matching that could be used in such cases. I would simply create a query string separated by the delimiter (|) out of the $languages array, and use that in the query --

$query_string = implode("|", $languages);
SELECT * FROM software_capability where languages REGEXP $query_string

The result will be same using LIKE clause as given in other answer.