简体   繁体   English

mysql检查给定的字符串是否在没有FIND_IN_SET的逗号分隔列表中

[英]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恰好为string1string2string3所有行。


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. 在上面的查询中,将返回包含string1string2string3所有3条记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在mysql中用逗号分隔的字符串连接find_in_set结果 - How to concat find_in_set results with comma separated string in mysql MySQL列搜索逗号分隔的项目-FIND_IN_SET或LIKE - MySQL column search for comma separated items - FIND_IN_SET or LIKE MySQL查询-逗号分隔列上的Find_in_set - MySQL Query - Find_in_set on comma separated columns MySQL-FIND_IN_SET用于逗号分隔的字段值 - MySQL - FIND_IN_SET for comma separated field values 我如何在没有find_in_set的情况下如何在mysql中的逗号分隔字符串中存在单个数字 - How can i get single number exist in comma seprated string in mysql without find_in_set mysql查询中find_in_set中的逗号分隔字符串是否有任何限制 - Is there any limit to the comma delimited string in find_in_set in mysql query 如何用mysql查找逗号find_in_set - how to find a comma with mysql find_in_set 其他函数,例如FIND_IN_SET,它返回逗号分隔列表中可用的字符串数 - Other function like FIND_IN_SET which returns number of strings available in comma separated list 如何使用IN,FIND_IN_SET比较逗号分隔字符串中的多个值? - How to compare multiple value in comma separated string using IN, FIND_IN_SET? 我的sql IN()函数或FIND_IN_SET函数允许的最大逗号分隔字符串 - The max comma separated string allowed in my sql IN() Function or FIND_IN_SET Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM