0Pricing
Excel Formulas Academy · Lesson

Querying Data With QUERY

Select, filter, and group data using SQL-like syntax in Sheets.

Querying Data With QUERY is a free Excel Formulas Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Excel Formulas Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What QUERY Does

Google Sheets has one function that feels like a tiny database language: QUERY. It lets you select, filter, and summarize data using a syntax very close to SQL.

Instead of stacking FILTER, SORT, and SUMIF together, you write one readable instruction. For example, show me only the East region rows, sorted by sales becomes a single formula.

QUERY is unique to Google Sheets. Excel does not have it, so this whole lesson is Sheets-only.

The Basic Syntax

QUERY takes three parts:

  • data the range to read, like A1:D100
  • query a text string of instructions, in quotes
  • headers an optional number telling QUERY how many header rows there are

The query string is where the magic lives. It always goes inside double quotes.

=QUERY(A1:D100, "SELECT A, B", 1)

Selecting Columns

The SELECT clause chooses which columns to return. Inside QUERY you refer to columns by their sheet letters (A, B, C), not by header names.

Use SELECT * to return every column, or list specific ones to keep only what you need. The order you list them in is the order they appear in the result.

=QUERY(A1:D100, "SELECT C, A, B", 1)

A Sample Dataset

Imagine a sales sheet in A1:D7 with headers Region, Rep, Product, Sales:

  • A: Region (East, West)
  • B: Rep (Ann, Bo, Cy)
  • C: Product (Pens, Paper)
  • D: Sales (numbers)

We will use this dataset for the rest of the lesson. Picture it whenever you see a QUERY formula below.

Filtering With WHERE

The WHERE clause keeps only rows that pass a test. Compare a column to a value using operators like =, >, <, and >=.

Text values go in single quotes inside the query string, because the whole query is already wrapped in double quotes.

=QUERY(A1:D7, "SELECT A, B, D WHERE A = 'East'", 1)

Comparing Numbers

Number filters do not need quotes. To see only the high-value sales, compare column D directly to a number.

This returns just the rows where Sales is greater than 500, keeping your report focused on the important deals.

=QUERY(A1:D7, "SELECT B, C, D WHERE D > 500", 1)

Combining Conditions

Use AND and OR to combine tests, just like in SQL.

  • AND requires both conditions to be true
  • OR needs at least one to be true

This example keeps East-region rows that also broke 300 in sales.

=QUERY(A1:D7, "SELECT A, B, D WHERE A = 'East' AND D > 300", 1)

Limiting Rows

Add LIMIT to cap how many rows come back. This is handy for top-N previews or for keeping a dashboard tidy.

Here we ask for the first 3 matching rows only. Combine it with sorting later to build a real top-3 list.

=QUERY(A1:D7, "SELECT A, B, D WHERE D > 0 LIMIT 3", 1)

Why Single vs Double Quotes Matter

This trips up everyone at first. The entire query is one Sheets text string, so it uses double quotes. Any text you compare against must therefore use single quotes inside it.

Writing WHERE A = "East" breaks the formula because the inner double quote ends the string early. Always use WHERE A = 'East'.

=QUERY(A1:D7, "SELECT * WHERE C = 'Pens'", 1)

Referencing a Cell in the Query

You can make a query interactive by pulling a value from a cell. Because the cell value lives outside the quotes, you concatenate it with the & operator.

If cell F1 holds a region name, this formula filters by whatever the user typed there.

=QUERY(A1:D7, "SELECT A, B, D WHERE A = '" & F1 & "'", 1)

The Headers Argument

The third argument tells QUERY how many header rows your data has. Pass 1 when the first row holds labels like Region and Sales.

If you omit it, QUERY guesses, and it sometimes guesses wrong, mixing a header into your results or treating numbers as text. Stating 1 explicitly keeps results predictable.

=QUERY(A1:D7, "SELECT A, D WHERE D > 100", 1)

Quick Check

Test your understanding of QUERY basics.

Recap

You learned the heart of Google Sheets QUERY:

  • QUERY(data, query, headers) is the structure
  • SELECT picks columns by letter; * means all
  • WHERE filters rows, combined with AND and OR
  • Text uses single quotes; numbers use none
  • & injects cell values for interactive filters

Next you will sort and group those results into summaries.

=QUERY(A1:D7, "SELECT A, B, D WHERE A = 'East' AND D > 300 LIMIT 5", 1)

Frequently asked questions

Is the “Querying Data With QUERY” lesson free?

Yes — the full text of “Querying Data With QUERY” is free to read here on the web, and the Excel Formulas Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Excel Formulas Academy course, upgrade to CoddyKit PRO.

What will I learn in “Querying Data With QUERY”?

Select, filter, and group data using SQL-like syntax in Sheets. You practise Excel Formulas Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Excel Formulas Academy?

No prior experience is required. Excel Formulas Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Querying Data With QUERY” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Excel Formulas Academy lesson?

Yes. Every Excel Formulas Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Querying Data With QUERY
  2. Sorting and Grouping in QUERY
  3. Applying Formulas to Columns With ARRAYFORMULA
  4. Pulling Data With IMPORTRANGE
← Back to Excel Formulas Academy