SQL - How do I escape underscore?
I'm trying to use LIKE to filter that needs to take into account the underscore for example _BR_.
However LIKE '%_BR_%' will just ignore the underscores.
Could someone point me to the right direction? Will this work? %[_]BR[_]%?
Thanks a lot!
Hi Vy, thanks for reaching out! You can use something like this to include underscores in a LIKE operator:
SELECT * FROM tableName WHERE columnName LIKE '%/_%' ESCAPE '/'
The underscore is the wildcard in a LIKE query for one arbitrary character. HenceLIKE %_% means "give me all records with at least one arbitrary character in this column". The ESCAPE operator prevents this from occurring. Let me know if you have any further questions!