0

I am super newbe in SQL-mySQL stuff and I want to query these entries that contain a column with a specific value but the value already has quotation marks in it, it literally looks like this, quotation marks are already there: "Museum Voor Land-en Volkenkunde, Rotterdam, Holland" So I tried:

SELECT * FROM this_table WHERE museum_name LIKE "Museum Voor Land-en Volkenkunde, Rotterdam, Holland";

returns Empty set (0.00 sec) which I know for a fact, is not true! then I tried (I tried both with double quotes, with single quotes, nothing works)

select * from this_table where museum_name=" "Museum Voor Land-en Volkenkunde, Rotterdam, Holland" ";

returns: ERROR 1064 (42000): 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 'Museum Voor Land-en Volkenkunde, Rotterdam, Holland" "' at line 1

Please let me know how I can query something specific if it already contains quotation marks.

Jen
  • 161
  • 2
  • 7

3 Answers3

0

Try like this

SELECT * FROM this_table WHERE museum_name LIKE '"Museum Voor Land-en Volkenkunde, Rotterdam, Holland"';

OR

SELECT * FROM this_table WHERE museum_name LIKE "\"Museum Voor Land-en Volkenkunde, Rotterdam, Holland\"";

To scape the quotes.

drosam
  • 2,866
  • 3
  • 16
  • 18
0

You can either just use the escape character \ or use single quotes ' or use % in LIKE clause.

Like this:

SELECT * FROM this_table WHERE museum_name LIKE "%Museum Voor Land-en Volkenkunde, Rotterdam, Holland%";

OR

SELECT * FROM this_table WHERE museum_name = "\"Museum Voor Land-en Volkenkunde, Rotterdam, Holland\"";

OR

SELECT * FROM this_table WHERE museum_name = '"Museum Voor Land-en Volkenkunde, Rotterdam, Holland"';
Sameer Mirji
  • 2,135
  • 16
  • 28
0

you should escape the string by using backsalsh \

like

 SELECT * FROM <tbl> WHERE col1 = "gh\"gh"

or

 SELECT * FROM <tbl> WHERE col1 = 'gh"gh'

both will work, but it is better to use first approach

developerCK
  • 4,418
  • 3
  • 16
  • 35