Php mysql查询匹配精确的字符串或数字

Php mysql查询匹配精确的字符串或数字,php,mysql,mysqli,Php,Mysql,Mysqli,我在MySQL表中找到了结果。 我只需要在用户id中只有6而不是26的地方得到结果 id users_id 15 6,5 16 1,5 18 2,8 19 1,26 20 6,26 21 5,10 22 28,6 23 21,9 24 29,6 我正在使用MySQL查询 SELECT * FROM WHERE users_id LIKE '%6%' id user_id 15 6,5 19 1,26

我在
MySQL
表中找到了结果。 我只需要在用户id中只有6而不是26的地方得到结果

id   users_id

 15    6,5
 16    1,5
 18    2,8
 19    1,26
 20    6,26
 21    5,10
 22    28,6
 23    21,9 
 24    29,6
我正在使用MySQL查询

SELECT * FROM WHERE users_id LIKE '%6%'
id  user_id

15  6,5
19  1,26   why is this here..
20  6,26
22  28,6
24  29,6
结果

SELECT * FROM WHERE users_id LIKE '%6%'
id  user_id

15  6,5
19  1,26   why is this here..
20  6,26
22  28,6
24  29,6
结果不正确。 我只需要:

id  user_id

15  6,5
22  28,6
24  29,6
来源


因为您的查询检查结果是否在每个位置都包含6

显然,26包含6

你可以这样做(存在其他方式)

试试看:

SELECT  *
FROM    tableName
WHERE   user_id like '6,%' or user_id like '%,6' or user_id like '%,6,%'
也许可以试试:

SELECT * FROM WHERE users_id IN ('6');
应该正好匹配6


或者在不知道“在集合中查找”或“或”的情况下,您可以:

id users_id 15 |6|5| 16 |1|5| 18 |2|6| 用户识别码 15 |6|5| 16 |1|5| 18 |2|6|
并选择像“%”6“%”这样的用户id。

对于像“%”6“这样的查询,若表中有许多行,则可能会出现性能问题。