Example Table (Person_data)
Name | Area | Id
===============================
Jack | A_102 | 102
Roy | Abc-34 | 109
tom | ABC6778 | 107
Aly | hj23 | 122
Saly | dsfds | 342
I need a query such that it returns all the rows where Area column doesn’t contain _ or - or Abc or ABC.
My query
Select * from Person_data
where area not like '%-%'
or area not like '%_%'
or area not like '%Abc%'
or area not like '%ABC%';
You need to combine these search conditions with
AND‘s, but the problem is the_which is a a reserved wildcard in theLIKEpredicate. You have to escape it in theLIKEpredicate using[]or you can determine any escape character to use to escape it using theESCAPEkeyword something likeLIKE '%\_%' ESCAPE '\', therefore it will treated like a literal, and it is the standard way to that like so:Here is a SQL Fiddle demo