+4 votes
in Databases by (27.2k points)
edited by

In a table, one column has substrings with "/"(forward slash) and "\"(backslash).

E.g.  "discussion\/"

I am running the following SQL to find rows with such substring, but my SQL returns 0 rows even when there are many such rows. What is wrong with my query?

SELECT * FROM my_table WHERE my_column LIKE '%discussion\/%';

1 Answer

+2 votes
by (45.8k points)

The way you have written the SQL "LIKE" statement to search strings with "/"(forward slash) and "\"(backslash) will not work.

You have to escape the "\" (backslash) with "\\" (double backslash) and "/" (forward slash) with "\" (single backslash).

So, your SQL should look like the following SQL:

SELECT * FROM my_table WHERE my_column LIKE '%discussion\\\\/%';

There are 3 extra "\": 2 for "\" and 1 for "/".

Related questions

+4 votes
1 answer
+2 votes
1 answer
+3 votes
1 answer
asked Jan 16, 2016 in Databases by praveen (18.6k points)

...