SQL

Compound Searching Using The SQL WHERE Statement With The IN Operator

One of the most important aspects of searching for objects is to be able to define multiple values in a search. We looked at searching using text globbing. But the IN operator goes a step and allows you to search
The IN operator allows you to specify multiple values in a WHERE clause.

SELECT column
FROM table
WHERE column IN (value,value,...);

In this article, we’ll use the same “Customers” table from our first articles:

ID Site Contact Address City Zip Country
1 Krypted Charles Edge my house Minneapolis 55418 US
2 Apple Tim Cook spaceship Cupertino 95014 US
3 Microsoft Satya Nadella campus Redmond 98053 US
4 Facebook Mark Zuckerberg foodhall Menlo Park 94025 US
5 JAMF Dean Hager Grain Exchange Minneapolis 55418 US

The following outputs all customers with a Site of “Krypted” or “JAMF”:

SELECT * FROM Customers
WHERE Site IN ('Krypted','JAMF');

When looking to use the IN operator, note that strings are quoted and separated by commas (,) inside parenthesis.