How to Use Multiple Criteria in Query using Query function
Using multiple criteria in a query using the Query function in Google Sheets involves combining multiple conditions in your query string. You can use the AND or OR operators to combine multiple conditions.
Here's a step-by-step guide on how to use multiple criteria in a query:
- Open your Google Sheet and prepare the data set you want to query.
- In an empty cell, type the Query function:
=QUERY()
- Inside the parentheses, specify the data range you want to query. For example, if your data is in cells A1 to D10, you would write:
=QUERY(A1:D10,
- Next, add your query string in double quotes. Start with
SELECT * WHERE
. For example:=QUERY(A1:D10, "SELECT * WHERE",
- Now, add your first condition, referencing the column letter from your data range. For example, if you want to find rows where column A contains the text "Apple", you would write:
=QUERY(A1:D10, "SELECT * WHERE A = 'Apple' AND",
- Add your second condition with the AND or OR operator. For example, if you want to find rows where column B is greater than 100, you would write:
=QUERY(A1:D10, "SELECT * WHERE A = 'Apple' AND B > 100",
- Close the double quotes and add a closing parenthesis for the Query function. The final formula looks like this:
=QUERY(A1:D10, "SELECT * WHERE A = 'Apple' AND B > 100")
- Press Enter to execute the query.
Example
Let's say you have the following data set in cells A1 to D5:
Product Quantity Price Category
Apple 150 1.20 Fruit
Banana 75 0.50 Fruit
Carrot 200 0.75 Vegetable
Orange 50 0.80 Fruit
Potato 300 0.40 Vegetable
You want to find rows where the Category is "Fruit" and the Quantity is greater than 100. Here's the query formula you would use:
=QUERY(A1:D5, "SELECT * WHERE D = 'Fruit' AND B > 100")
The result will be:
Product Quantity Price Category
Apple 150 1.20 Fruit
Did you find this useful?