Reputation: 17057
I need to search for strings containing the character ` in mysql I am trying:
select * from transactions where transactions.calculatorCode like "%`%";
but it's returning ALL records. Am I missing something?
Upvotes: 0
Views: 177
Reputation: 10206
You should first check if the ANSI_QUOTES mode is enabled on your server
mysql> SELECT @@sql_mode;
If you see it in the results, then you should surround your strings litterals with only single quotes because double quotes will interpret them as IDENTIFIERS (column, table, etc...) and not strings, which is the standard SQL behaviour.
So your query should become
select * from transactions where transactions.calculatorCode like '%`%';
Anyway, you should avoid using double quotes to surround your strings because your SQL code portability will be badly affected. Always use single quotes is a rule of thumb.
If it still doesnt work, you can try a REGEXP_LIKE instead:
select * from transactions WHERE REGEXP_LIKE(calculatorCode, '`');
select * from transactions WHERE calculatorCode RLIKE '`';
Upvotes: 1