Confused about mysql as an escaped query?
I have a table below data
select * from t;
+----+----------------+
| id | a |
+----+----------------+
| 1 | u5929u732b |
| 2 | \u5929\u732b |
| 3 | \\u5929\\u732b |
+----+----------------+
The query result is used equal
select * from t where a = '\u5929\u732b';
+----+------------+
| id | a |
+----+------------+
| 1 | u5929u732b |
+----+------------+
select * from t where a = '\\u5929\\u732b';
+----+--------------+
| id | a |
+----+--------------+
| 2 | \u5929\u732b |
+----+--------------+
select * from t where a = '\\\\u5929\\\\u732b';
+----+----------------+
| id | a |
+----+----------------+
| 3 | \\u5929\\u732b |
+----+----------------+
these results are the same as i expected so no problem then i used to query the result and at this time i am very confused
# as I expected
select * from t where a like '\u5929\u732b';
+----+------------+
| id | a |
+----+------------+
| 1 | u5929u732b |
+----+------------+
# I do not understand I think it should return result of id = 2
select * from t where a like '\\u5929\\u732b';
+----+------------+
| id | a |
+----+------------+
| 1 | u5929u732b |
+----+------------+
# I think it should return result of id = 3
select * from t where a like '\\\\u5929\\\\u732b';
+----+--------------+
| id | a |
+----+--------------+
| 2 | \u5929\u732b |
+----+--------------+
So why is a request like
different from an equal request?
source to share
\
is an escape character in mysql. This means that the statement
select * from t where a like '\\u5929\\u732b';
equivalent to
select * from t where a like 'u5929u732b;
therefore the correct answer is correct.
So your third request ( select * from t where a like '\\\\u5929\\\\u732b';
) is a request with a request
select * from t where a like '\\u5929\\u732b;'
,
and therefore the statement that you can use to get the desired result is also correct!
source to share