Hello friends, In this post, you will see how you can use NOT LIKE operator in soql query and dynamic soql query.

Not like operator in soql

Here i am posting query example on different scenarios.

Scenario 1: Select all Account records with Name not starts with 'AW'.

 List<Account> lstAcc=[SELECT Name, Industry FROM Account WHERE Not Name Like 'AW%'];
In Dynamic SOQL
 List<Account> lstAcc=DataBase.query('SELECT Name, Industry FROM Account WHERE Not Name Like \'AW%\'');
Scenario 2: Select all Account records with Name not ends with 'AW'.
 List<Account> lstAcc=[SELECT Name, Industry FROM Account WHERE Not Name Like '%AW'];
In Dynamic SOQL
List<Account> lstAcc=DataBase.query('SELECT Name, Industry FROM Account WHERE Not Name Like \'%AW\'');
Scenario 3: Select all Account records with 'AW'  not in between Name.
 List<Account> lstAcc=[SELECT Name, Industry FROM Account WHERE Not Name Like '%AW%'];
In Dynamic SOQL
 List<Account> lstAcc=DataBase.query('SELECT Name, Industry FROM Account WHERE Not Name Like \'%AW%\'');
You can use "GROUP BY" clause with "Not Like" operator.
 List<Account> lstAcc=[SELECT Name From Account Where Not Name Like '%Test%' GROUP BY Name];

Output: 

 

Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.