LIKE运算符中的多个条件
问题描述:
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%'
我在这个$语言中得到多个值,如(php,Ruby)我希望溢出,以及如何检查 在此查询中拆分值 p>
SELECT * FROM software_capability其中语言LIKE'%$ languages%'
code> pre>
div>
答
Try with this.
SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%')
This is syntax. Exploded your $language and put each item in '%$item%'
答
SELECT * FROM software_capability where CONCAT('%',languages,'%') LIKE '$languages';
assuming that $languages is 'php,Ruby'
答
If $languages
is comma (,) separated values, then you can try with IN
command of mysql
SELECT * FROM software_capability where languages IN ($languages)
答
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.