+4 votes
in Databases by (63.4k 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 (271k points)
selected by
Best answer

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
+3 votes
1 answer
asked Jan 16, 2016 in Databases by praveen (63.0k points)
+2 votes
1 answer