Sometimes, we need the inverse of a condition, or cases WHERE
a value does not equal something. To do this, we prefix our equals with the "not operator", !=
, to invert the condition.
For example, to retrieve a list of Opportunities that are not in the 'Closed Won' stage, we can use the following query:
SELECT Name, StageName, Type FROM Opportunity WHERE StageName != 'Closed Won'
Name | StageName | Type |
---|---|---|
Dickenson Mobile Generators | Qualification | New Customer |
United Oil Office Portable Generators | Negotiation/Review | Existing Customer - Upgrade |
Grand Hotels Kitchen Generator | Id. Decision Makers | Existing Customer - Upgrade |
... | ... | ... |
Let's say you want to look at all the global accounts, excluding those in the United States. 🌍
SELECT Name, AnnualRevenue, BillingCountry FROM Account WHERE BillingCountry != 'United States'
Name | AnnualRevenue | BillingCountry |
---|---|---|
Edge Communications | 139000000 | Argentina |
Burlington Textiles Corp of America | 350000000 | France |
Pyramid Construction Inc. | 950000000 | Egypt |
... | ... | ... |
Additionally, let's say we want to find all the Contacts with an Email so we can put together our distribution list. We can do this by looking for Contacts WHERE
their Email
is not null.
SELECT Name, Email, Title FROM Contact WHERE Email != null
Name | Title | |
---|---|---|
Rose Gonzalez | rose@edge.com | SVP, Procurement |
Sean Forbes | sean@edge.com | CFO |
Jack Rogers | jrogers@burlington.com | VP, Facilities |
... | ... | ... |
Similar to our numeric equality comparison, when using the !=
for numbers, we just specify the value without any ’
single quotes. For example, this query will retrieve all Opportunities that do not have a 100% probability of closing.
SELECT Name, Probability, StageName FROM Opportunity WHERE Probability != 100
Name | Probability | StageName |
---|---|---|
Dickenson Mobile Generators | 10 | Qualification |
United Oil Office Portable Generators | 90 | Negotiation/Review |
Grand Hotels Kitchen Generator | 60 | Id. Decision Makers |
... | ... | ... |