Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do you escape a question mark character in a string on the MySQL CLI?

There are many methods to avoid having to escape characters, but from an ease-of-use perspective I would quite like to do some SELECT statements containing LIKE queries, some of which contain question marks and the usual \? does not work.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

LIKE doesn't use ?. LIKE uses % and _.

share|improve this answer
    
Same question with a WHERE = then. –  Metalshark Dec 8 '10 at 14:33
    
= doesn't use any wildcards. –  Ignacio Vazquez-Abrams Dec 8 '10 at 14:35
    
I am looking for the string <a href="/about?param=value"> in a CMS. Performing SELECT uid FROM cms_table WHERE html LIKE '%/about%' works, however SELECT uid FROM cms_table WHERE html LIKE '%/about?%' doesn't. I cannot seem to escape the question mark and make it part of the statement. The same thing happens when using a plain WHERE =. –  Metalshark Dec 8 '10 at 14:39
    
Thank you! There is something weird going on with this database, I'll look at character encodings... –  Metalshark Dec 8 '10 at 14:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.