使用逗号分隔值的SELECT mysql列 [英] SELECT mysql column with comma separated values
本文介绍了使用逗号分隔值的SELECT mysql列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑我有一个这样的表.
Consider I have a table like this.
+-------------+---------------+----------------+---------------+
+ id + column 1 + column 2 + column 3 +
+-------------+---------------+----------------+---------------+
+ 1 + values + values + a, b, c, d, e +
+-------------+---------------+----------------+---------------+
我的查询可以是这样
SELECT * FROM table WHERE column 1 = 'values' AND column 3 = '$variable'
$ variable可以是从a到e的任何值
The $variable can be anything from a to e
有没有一种方法可以使用查询来选择我想要的行?
Is there a way to use query to select the row the I want?
推荐答案
使用FIND_IN_SET()
-mysql的内置函数搜索字符串
use FIND_IN_SET()
-- a builtin function for mysql to search a string
SELECT *
FROM tableName
WHERE column 1 = 'values' and FIND_IN_SET('a',column 3 )>0
查看全文