Search code examples
sqlsql-serversql-like

Using `_%` together in `LIKE` is not returning exact data


I can guesss it may be easy to answer type question but I am facing it first time, so any help will be more appreciated.

My Query:

SELECT remarks FROM enroll WHERE remarks LIKE 'REC_%'

OUTPUT:

remarks
REC_59161
Reclassify Hedge

Expected Output is only REC_59161. Yes _ is used for matching any single character but I am just looking for achieving my expected output.


Solution

  • _ is a wildcard Character. So that you have to escape it using [].

    Query

    select remarks
    from enroll
    where remarks like 'REC[_]%';