0

in my query:

SELECT * FROM ecoprosys.dataset where name="1'-Hydroxyestragole";

My query does not work, because it confuses with the my string that already have a commas in it.

Kinchit Dalwani
  • 398
  • 4
  • 19
  • 1
    Try escaping it with another quote, like this: `name="1''-Hydroxyestragole"` – casraf Jul 18 '17 at 09:39
  • See: https://stackoverflow.com/questions/9596652/how-to-escape-apostrophe-in-MySQL for more help on this – WJS Jul 18 '17 at 09:44

5 Answers5

1

You need to escape the single quote present in your string literal. Try the query below:

SELECT * FROM ecoprosys.dataset where name='1''-Hydroxyestragole';
Keyur Panchal
  • 1,382
  • 1
  • 10
  • 15
0

Maybe you miss using the backslash '\' to do the escape character thing.

sql_cmd='SELECT * FROM ecoprosys.dataset where name=\'1\'-Hydroxyestragole\'';
Johnny Kuo
  • 91
  • 1
  • 7
0

You can try the following methods:

 SELECT * FROM ecoprosys.dataset where name='1''-Hydroxyestragole';
 SELECT * FROM ecoprosys.dataset where name='1'+char(39)+'-Hydroxyestragole';
0

$sql=SELECT * FROM ecoprosys.dataset where name='1''-Hydroxyestragole';

Sooraj J
  • 9
  • 1
  • 8
0

Single quotes are escaped by doubling them up

SELECT * FROM ecoprosys.dataset where name='1''-Hydroxyestragole';

Also

In SQL, values should be enclosed within single quote

Example: where name='john' and not name ="john"

Geetha Ponnusamy
  • 497
  • 3
  • 15