[英]mysql check if given string are in a comma separated list without FIND_IN_SET
SELECT * FROM TABLE_NAME WHERE 'string' in ('string1','string2','string3')
Its not given correct result find_in_set only given a exact result. 它没有给出正确的结果,find_in_set只给出了精确的结果。 If any way to get correct result without using
find_in_set
如果有任何不使用
find_in_set
来获得正确结果的方法
SELECT * FROM TABLE_NAME WHERE 'string' in ('string1','string2','string3');
SELECT * FROM TABLE_NAME WHERE'string'in('string1','string2','string3');
In the above query, string
is supposed to be a field (column) so, if you were to have this query work, it would be without single quotes '
, like this: 在上面的查询中,
string
应该是一个字段(列),因此,如果要进行此查询,它将没有单引号'
,如下所示:
SELECT * FROM TABLE_NAME WHERE string IN ('string1','string2','string3');
SELECT * FROM TABLE_NAME WHERE string IN('string1','string2','string3');
This will return all rows where the field string
is exactly string1
or string2
or string3
. 这将返回字段
string
恰好为string1
或string2
或string3
所有行。
Now, if you want to query the field string
for values like "string", not exactly matching, then you use the LIKE operator : 现在,如果要在字段
string
查询 “ string”之类的值 ,而不是完全匹配的值,则可以使用LIKE运算符 :
SELECT * FROM TABLE_NAME WHERE string LIKE '%string%';
SELECT * FROM TABLE_NAME WHERE string like'%string%';
In the above query, all 3 records containing string1
, string2
and string3
will be returned. 在上面的查询中,将返回包含
string1
, string2
和string3
所有3条记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.