MySQL LIKE query with underscore(带下划线的 MySQL LIKE 查询)
本文介绍了带下划线的 MySQL LIKE 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下表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 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:带下划线的 MySQL LIKE 查询


基础教程推荐
猜你喜欢
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01