4

I want to find data with double quotes. I have the next simple query:

SELECT * FROM table_name WHERE column_name LIKE "%\"%";

But I have syntax error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"%\"%' at line 1

What should I do to find this data with double quotes(")?

Alex Pliutau
  • 20,640
  • 26
  • 107
  • 142

5 Answers5

13

Because the \ character is used by the LIKE operator itself you have to double it when you use it to escape another character like the double quote.

see here

SELECT * FROM table_name WHERE column_name LIKE "%\\"%";

should work for you.

as will changing out the double quotes for single quotes to enclose the literal

SELECT * FROM table_name WHERE column_name LIKE '%"%';

as you posted here

Community
  • 1
  • 1
TetonSig
  • 2,089
  • 14
  • 21
3

try

SELECT * FROM table_name WHERE column_name LIKE '%"%';
diEcho
  • 52,196
  • 40
  • 166
  • 239
2

SELECT * FROM table_name WHERE column_name LIKE '%\"%'; this one is work.Check it.

1

Sorry, I have found the answer:

SELECT * FROM table_name WHERE column_name LIKE '%"%';
Alex Pliutau
  • 20,640
  • 26
  • 107
  • 142
0

If in database fields has both single and double quotes then in query follow below syntex:

"select id,name 
from table_name 
where 
Replace(
Replace(name, \"'\", '`' ),'\"','`')='".value."'