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
Name | Phone | |
---|---|---|
Edna Frank | efrank@genepoint.com | |
Avi Green | (212) 842-5500 | agreen@uog.com |
Jo Temlett | ||
Jase Baillie | jbaillie1@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'
Name | Type | BillingCountry |
---|---|---|
Burlington Textiles Corp of America | Customer - Direct | USA |
Dickenson plc | Customer - Channel | USA |
O'Connell-Macejkovic | Installation Partner | United States |
... | ... | ... |
We could keep going, OR
we can put those skills to work.