SOQL Logical Operators

When we need to filter rows using several conditions, we have to use Logical operators allow you to apply multiple comparison operators in one query.

Here is a list of logical operators available in SOQL:

The SQL AND operator

Allows you to select only rows that satisfy two conditions.

Example: Find all clinics which are open on holidays in Florida.

SELECT Id, Name
FROM Clinic__c
WHERE is_Open_on_holidays__c = True
AND State__c = 'Florida'

The SQL OR operator

Allows you to select rows that satisfy either of two conditions.

Example: Find all clinics which are located in Florida or Chicago

SELECT Id, Name
FROM Clinic__c
WHERE State__c = 'Florida' 
OR state__c = 'Chicago'

The SQL NOT operator

Allows you to select rows that do not match a certain condition.

Example: Find all clinics which are NOT located in Florida or Chicago.

SELECT Id, Name
FROM Clinic__c
WHERE NOT (state__c = 'Florida' OR state__c = 'Chicago' )