我有下表images
:
+----+--------------+
| id | img_path |
+----+--------------+
| 1 | abc_1.jpg |
| 2 | abc_2.jpg |
| 3 | abcde_1.jpg |
| 4 | abcde_2.jpg |
| 5 | abcdef_1.jpg |
+----+--------------+
我想选择img_path
以abc_
开头的条目,所以我使用以下查询:
I would like to select the entries that img_path
starts with abc_
, so I use the following query:
SELECT id FROM images WHERE img_path LIKE 'abc_%'
但它返回所有 5 行.我如何只返回 id
= 1 &2(哪个img_path
以abc_
开头)?
But it returns all 5 rows. How do I only returns id
= 1 & 2 ( which img_path
starts with abc_
) ?
发现 _
是一个特殊字符.必须使用反斜杠转义.
Found out that _
is a special character. Have to escape with backslashes.
SELECT id FROM images WHERE img_path LIKE 'abc\_%'
按预期返回 2 行
这篇关于带下划线的 MySQL LIKE 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!