5

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
  • 21,392
  • 27
  • 113
  • 143

5 Answers5

16

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,189
  • 15
  • 21
3

try

SELECT * FROM table_name WHERE column_name LIKE '%"%';
xkeshav
  • 53,360
  • 44
  • 177
  • 245
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
  • 21,392
  • 27
  • 113
  • 143
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."'