[英]select with IN gives wrong result
Field editors value '3,2,4'
现场编辑者将
value '3,2,4'
sql statement sql语句
SELECT * FROM `table` where '3' in (editors)
result 1 row = correct 结果1行=正确
SELECT * FROM `table` where '2' in (editors)
result 0 row = not correct. 结果0行=不正确。
I presume the value '3,2,4'
is treated as a string, how to solve this? 我假设
value '3,2,4'
被当作一个字符串,如何解决呢?
You'll have to use FIND_IN_SET()
, or a hideous construct like 您必须使用
FIND_IN_SET()
或类似的可怕构造
WHERE editors='2'
OR editors LIKE '2,%'
OR editors LIKE '%,2,%'
OR editors LIKE '%,2'
Right now your query is being interpreted as 现在,您的查询被解释为
WHERE '2' IN ('1,2,3')
a.k.a
WHERE '2' = '1,2,3'
and not 并不是
WHERE '2' IN ('1', '2', '3')
a.k.a.
WHERE '2' = '1' OR '2' = '2' OR '2' = '3'
like you want it to. 就像你想要的那样。 WHERE
哪里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.