0

I wanted to inquire if it is important to treat the backslashes in a SQL statement in order to get the correct counts? This is an example:

Select users from table1 where screenname like '/welcome?optin=%'

Do I need to inject additional treatment to the special characters in the like statement to ensure correct counts? I do not get an error running this query but I wonder if it is returning more counts than it should.

LaLaTi
  • 1,455
  • 3
  • 18
  • 31
  • 1
    The only chars that need additional treatment (escaping) when you use LIKE would be `%` and `_`. Slash and backslash are not special chars: https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_like – forpas Dec 06 '19 at 19:18
  • Ah, does it mean in my statement needs treatment due to the "%" character only? – LaLaTi Dec 06 '19 at 19:21
  • No, the only case that % and _ need escaping is if you want to match these chars. If you want them to behave like wildcards then you don't have to do anything. – forpas Dec 06 '19 at 19:22
  • In my case, the characters in the string represent the exact string and not wildcards. In this case then, I need treatment due to the existing %, yes? – LaLaTi Dec 06 '19 at 19:24
  • [This](https://stackoverflow.com/questions/5020130/how-to-escape-literal-percent-sign-when-no-backslash-escapes-option-is-enabled/5020292) will show you how to escape that. – Rob Moll Dec 06 '19 at 19:26
  • 2
    If this is the case then yes, but why then you don't use `=` instead of LIKE? – forpas Dec 06 '19 at 19:27

0 Answers0