在mysql中使用撇号搜索记录,如查询

时间:2013-06-27 07:52:02

标签: mysql

我有类似这样的mysql查询。

SELECT * from users where username LIKE "%test\'s%"

拥有users数据库表,字段名称为username

users表中有1条记录,用户名为test\'s,现在我想根据username从用户表中查询获取记录的查询。但它不起作用。

请帮助我解决这个问题。

我们将不胜感激。

4 个答案:

答案 0 :(得分:5)

我有同样的问题,我使用下面的代码解决了它。

SELECT *
FROM users
WHERE `username` = 'test\\''s'

希望这也适合你。

答案 1 :(得分:1)

SQL语法应为:

SELECT * from users where username LIKE '%test''s%'

答案 2 :(得分:0)

SELECT * from users WHERE username LIKE CONCAT('%', 'test\\\'s', '%');

答案 3 :(得分:0)

SELECT * from users where username = 'test''s'
相关问题