I am trying to search for backslashes and percentages in a select statement. I understand that I need six backslashes to search the following records
| id | name |
|---|---|
| 1 | \ |
select * from test_table where name like '%\\\\\\%'
However, to search for the following records requires six backslashes and four backslashes, not six and six.
| id | name |
|---|---|
| 2 | \a\ |
select * from test_table where name like '%\\\\\\a\\\\%';
-- select * from test_table where name like '%\\\\\\a\\\\\\%'; ←unsearchable
What is the reason that the number of backslashes to escape depends on their position?
- MySQL: 5.7.34
- table/column collation: utf8_unicode_ci