一张表,数据如下
+----------------+------------------+
| id | branchIdList |
+----------------+------------------+
| 1 | 1,2,3,4 |
+----------------+------------------+
一张表有两个字段 id,searchField
,假如有个 变量 $branchId
,
判断这个变量在没在branchIdList
里面
我之前会用 where $branchId
like %branchIdList%
, 但是这样会造成误差
比如这样 :
$branchId = 5;
+----------------+------------------+
| id | branchIdList |
+----------------+------------------+
| 1 | 1,2,3,4,55 |
+----------------+------------------+
这样就会出现很大的误差
解决办法:
用MySQL的find_in_set()
函数,自动支持逗号分割
select * from table where find_in_set($branchId, branchIdList)