OR Operator
Not Started

OR, in some cases, we want either of our conditions to be true. Selecting information that meets a certain criteria OR another criteria.

In our sample dataset, some of the Contact data is incomplete. Some contacts are missing emails, while others are missing phone numbers. To write a query to retrieve these, we'll need to filter for contacts whose email or phone field has a null value.

SELECT Name, Phone, Email FROM Contact WHERE Phone = null OR Email = null

NamePhoneEmail
Edna Frankefrank@genepoint.com
Avi Green(212) 842-5500agreen@uog.com
Jo Temlett
Jase Bailliejbaillie1@si.edu
.........



We can also filter records based on multiple conditions related to a single field. For instance, when searching for Accounts located in the U.S., we may encounter data inconsistencies. To handle different possible formats, we can specify in our query to find Accounts where the 'Billing Country' is either 'USA' or 'United States' in our query. This statement uses the OR logical operator to catch both possible entries:

SELECT Name, Type, BillingCountry FROM Account WHERE BillingCountry = 'USA' OR BillingCountry = 'United States'

NameTypeBillingCountry
Burlington Textiles Corp of AmericaCustomer - DirectUSA
Dickenson plcCustomer - ChannelUSA
O'Connell-MacejkovicInstallation PartnerUnited States
.........



We could keep going, OR we can put those skills to work.

Challenge

Write a query to retrieve the Name, Stage, and Type for all Opportunities that have these types:

  • Existing Customer - Downgrade
  • Existing Customer - Replacement
  • Existing Customer - Upgrade