我几乎是mysql的新手。
我想编写一个查询来搜索关键字以逗号分隔的列中的特定关键字。但是当我使用以下代码时,它只返回我只有那个特定关键字的行,而不是与任何其他关键字组合。
在表q16中,我正在寻找一种方法来选择在“Area_of_concern”列中包含我的关键字的行,无论它是否与其他关键字结合使用:
SELECT *
FROM `q16`
WHERE area_of_concern like '%more education is needed%'
这是一个输入示例:
q16_id关注领域
1 more education is needed
2 more enforcement, change in strategy
3 change in strategy
4 more education is needed, change in strategy
5 transportation issue, more enforcement, more education is needed
我希望获得关键字“需要更多教育”的行。所以我应该在输出中看到第1,4,5行
答案 0 :(得分:0)
I think you should create a table where you have one column for keywords and one column for where those keywords are used: a foreign key for the q16 table in your case.
It will work much faster that way.
As for your question it is a duplicate of this one here, I believe.
How to search for rows containing a substring?
A quick try: try using double quotes instead of single ones, as in some systems, single quotes don't allow for escapes (special characters) inside them.