SOQL Where Clause

The SOQL WHERE clause is used to filter records that match a certain condition. For example, you could use the following query to return every account with the billing country equal to France:

SELECT Id, Name, BillingCountry
FROM Account
WHERE BillingCountry = 'France'

We can also combine multiple logical tests in our WHERE clause using AND or OR. If, for example, in our previous query, we only wanted to return the accounts with billing country equal to France that also had a billing city equal to ‘Paris’, we could use AND to specify both conditions.

SELECT Id, Name, BillingCountry, BillingCity
FROM Account
WHERE BillingCountry = 'France'
AND BillingCity = 'Paris'

The following table show how to filter rows depending on field data type:

A string value is enclosed in single quotes
Country__c = 'USA'
A number value is written directly
Max_no_of_appointments__c  > 100
A boolean value is written as either true/false
Open_in_holiday__c = true
A date is written in this format (yyyy-mm-dd)
CreateDate > 2019-01-31
A datetime is written in this format (yyyy-mm-ddThh:mm:ssZ)
CreateDate < 2019-01-31T10:00:00-08:00

Note that a value can also be a date literal like (appointment_date__c = TODAY) which we will explain later.