How to Use WHERE IN a List using Query function

To use WHERE IN a list using the QUERY function in Google Sheets, you need to follow these steps:

  1. Organize your data in columns with proper headings.
  2. Create a list of values that you want to use with the WHERE IN clause.
  3. Use the QUERY function and include the WHERE IN clause with the list of values.

Here's an example to better understand the process:

Example

Suppose you have the following dataset in the range A1:C6:

Name | Age | City
John | 25  | New York
Jane | 30  | Chicago
Bob  | 20  | Los Angeles
Lily | 28  | New York
Sam  | 35  | Miami

You want to filter the data to display only the records for people living in New York and Los Angeles.

  1. First, create a list of cities you want to filter by. For instance, you can create a list in cell E1 with the values "New York" and "Los Angeles" separated by commas:
New York, Los Angeles
  1. Next, use the QUERY function to filter the data using the WHERE IN clause:
=QUERY(A1:C6, "SELECT * WHERE C IN ('New York', 'Los Angeles')", 1)
  1. Press Enter, and you will get the filtered result:
Name | Age | City
John | 25  | New York
Bob  | 20  | Los Angeles
Lily | 28  | New York

In the QUERY function, the first argument (A1:C6) is the data range, the second argument is the query string, and the third argument (1) is the number of header rows. The query string uses the WHERE IN clause to filter the data based on the list of cities provided in the parentheses.

Did you find this useful?