Skip to content

ESCAPE

SELECT *
FROM Employees
WHERE city LIKE '%\_r%' ESCAPE '\';
| Employee_Id | First_Name | Last_Name | City |
|-------------|------------|-----------|-----------|
| 1 | John | Smith | New York |
| 3 | James | Johnson | Marrakech |

In this example, the SQL query uses the ESCAPE keyword to specify the escape character (\). It helps in searching for a pattern that includes an underscore (_). The underscore is usually a special character that matches any single character in SQL pattern matching, but with the \ escape character before it, it’s treated as a literal underscore. So LIKE '%\_r%' matches any string containing ‘_r’.