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.
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.
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.
In the selected cell, type =QUERY( to begin the function.
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,
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".
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.
Advanced Tips for the QUERY Function
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.
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".
Combine conditions in your WHERE clause using AND and OR. For text, use single quotes: "WHERE C = 'Completed' AND D > 100".
Always refer to columns by their letter identifier (A, B, C) within the query string, not by their header text (e.g., 'Sales', 'Date').
Explore other Google Sheets guides and shortcuts