OverlayFlow

How to Use the QUERY Function in Google Sheets ?

Learn how to use the powerful QUERY function in Google Sheets to filter, sort, and analyze your data using a simple, SQL-like language. It's one of the most versatile functions for data manipulation.

Use the formula QUERYdata, query, headers to run a query.

How to Use the QUERY Function: A Step-by-Step Guide

1

Prepare Your Data

Ensure your data is in a structured range or table with clear column headers in the first row. For example, a dataset in columns A through D.

2

Select a Destination Cell

Click on an empty cell where you want the results of your query to appear. The function will output an array, so make sure there is enough empty space below and to the right.

3

Start the Formula

In the selected cell, type =QUERY( to begin the function.

4

Define the Data Range

Select the entire range of data you want to query, including the headers. For example, A1:D100. Your formula will look like: =QUERY(A1:D100,

5

Write the Query String

Type your query as a text string enclosed in double quotes. For example, to select columns A and B where column C is greater than 50, you would write "SELECT A, B WHERE C > 50".

6

Set the Headers Argument

Add a final argument to tell Google Sheets how many header rows are in your data range. It's usually 1. Your complete formula will look like: =QUERY(A1:D100, "SELECT A, B WHERE C > 50", 1). Press Enter to see the results.

💡 Pro Tips

Advanced Tips for the QUERY Function

📊

Sort Your Data

Use the ORDER BY clause to sort your results. For example, "SELECT * ORDER BY C DESC" sorts the data by column C in descending order.

Aggregate Data

Perform calculations with functions like SUM(), AVG(), COUNT(), and MAX(). Use the GROUP BY clause to group results. Example: "SELECT A, SUM(B) GROUP BY A".

🔍

Complex Filtering

Combine conditions in your WHERE clause using AND and OR. For text, use single quotes: "WHERE C = 'Completed' AND D > 100".

🔡

Column Identifiers

Always refer to columns by their letter identifier (A, B, C) within the query string, not by their header text (e.g., 'Sales', 'Date').

Need help right into Google Sheets?

Try Overlayflow, it's an AI software assistant that can answer any questions and show you on screen where to click!

Now available for any popular app.
3-day free trial. No credit card required. Then $59 one-time payment.