更新时间:2023-12-04 11:31:10
WHERE IN
要求在查询中按字面值指定一组值,而不是包含逗号分隔字符串的单个值.如果您写:
WHERE IN
requires the set of values to be specified literally in the query, not as a single value containing a comma-delimited string. If you write:
WHERE 6 IN (a.allowed_activity)
它将a.allowed_activity
视为单个值,并将其与6
进行比较,而不是将其作为多个要搜索的值的集合.
it will treat a.allowed_activity
as just a single value, and compare it with 6
, not as a set of multiple values to search.
FIND_IN_SET
在逗号分隔的字符串中搜索值.
FIND_IN_SET
searches a comma-delimited string for the value.
另一种查看方式是IN
是结合OR
的一堆=
测试的快捷方式:
Another way to view it is that IN
is a shortcut for a bunch of =
tests combined with OR
:
WHERE x IN (a, b, c, d)
是
WHERE x = a OR x = b OR x = c OR x = d
以这种方式重写它时,您可以清楚地知道为什么它不适用于包含逗号分隔的字符串的列.它只是翻译
When you rewrite it like this, you can see clearly why it won't work with a column containing a comma-delimited string. It simply translates
WHERE 6 IN (a.allowed_activity)
收件人:
WHERE 6 = a.allowed_activity