How to Use QUERY Function in Google Sheets (2026)

QUERY is the most powerful function in Google Sheets. It uses SQL-like syntax to filter, sort, group, and aggregate data all in one formula. Where you might use SUMIF, VLOOKUP, and FILTER separately, QUERY does it all at once. This 2026 tutorial teaches every essential QUERY pattern with real examples.

QUERY function syntax

=QUERY(data, query, [headers])
  • data: the range to query (e.g., A1:D100).
  • query: SQL-like statement in quotes (e.g., "SELECT A, B WHERE C > 100").
  • headers: optional. Number of header rows (default: auto-detect).

Basic SELECT examples

Return all columns:
=QUERY(A1:D100, "SELECT *")

Return only columns A, B, C:
=QUERY(A1:D100, "SELECT A, B, C")

Return column D and A (reordered):
=QUERY(A1:D100, "SELECT D, A")

Return unique values in column C:
=QUERY(A1:D100, "SELECT DISTINCT C")

WHERE clause (filtering)

Filter rows where B > 100:
=QUERY(A1:D100, "SELECT * WHERE B > 100")

Filter where C equals "Approved":
=QUERY(A1:D100, "SELECT * WHERE C = 'Approved'")

Multiple conditions with AND:
=QUERY(A1:D100, "SELECT * WHERE B > 100 AND C = 'Approved'")

Multiple conditions with OR:
=QUERY(A1:D100, "SELECT * WHERE C = 'Approved' OR C = 'Pending'")

Text contains (LIKE):
=QUERY(A1:D100, "SELECT * WHERE A LIKE '%phone%'")

Not equal:
=QUERY(A1:D100, "SELECT * WHERE C <> 'Rejected'")

Blank values only:
=QUERY(A1:D100, "SELECT * WHERE D IS NULL")

ORDER BY (sorting)

Sort by column B ascending:
=QUERY(A1:D100, "SELECT * ORDER BY B")

Sort descending:
=QUERY(A1:D100, "SELECT * ORDER BY B DESC")

Sort by multiple columns:
=QUERY(A1:D100, "SELECT * ORDER BY C ASC, B DESC")

Aggregation (GROUP BY)

Sum sales per customer:
=QUERY(A1:D100, "SELECT A, SUM(B) GROUP BY A")

Count orders per region:
=QUERY(A1:D100, "SELECT C, COUNT(A) GROUP BY C")

Average price per product:
=QUERY(A1:D100, "SELECT A, AVG(B) GROUP BY A")

Sales per region + product:
=QUERY(A1:D100, "SELECT A, C, SUM(B) GROUP BY A, C")

With ORDER BY:
=QUERY(A1:D100, "SELECT A, SUM(B) GROUP BY A ORDER BY SUM(B) DESC")

LIMIT and OFFSET

Top 10 records:
=QUERY(A1:D100, "SELECT * ORDER BY B DESC LIMIT 10")

Skip first 5, then take next 10:
=QUERY(A1:D100, "SELECT * LIMIT 10 OFFSET 5")

LABEL and FORMAT clauses

Custom column labels:
=QUERY(A1:D100, "SELECT A, SUM(B) GROUP BY A LABEL A 'Customer', SUM(B) 'Total Sales'")

Format numbers as currency:
=QUERY(A1:D100, "SELECT A, SUM(B) GROUP BY A FORMAT SUM(B) '$#,##0.00'")

Format dates:
=QUERY(A1:D100, "SELECT A, B FORMAT B 'yyyy-mm-dd'")

Using cell references in QUERY

Filter by value in cell F1:
=QUERY(A1:D100, "SELECT * WHERE C = '"&F1&"'")

Filter by number in cell F1:
=QUERY(A1:D100, "SELECT * WHERE B > "&F1)

Filter by date range (F1 = start, F2 = end):
=QUERY(A1:D100, "SELECT * WHERE B >= date '"&TEXT(F1,"yyyy-mm-dd")&"' AND B <= date '"&TEXT(F2,"yyyy-mm-dd")&"'")

Combining QUERY with IMPORTRANGE

Query data from another sheet:
=QUERY(IMPORTRANGE("SHEET_URL", "Sheet1!A1:D100"), "SELECT Col1, SUM(Col2) GROUP BY Col1", 1)

Note: use Col1, Col2 (not A, B) with IMPORTRANGE data.

Common QUERY errors

  • #VALUE! error: check quotes around text values inside WHERE. Text values need single quotes.
  • #REF! error: data range is invalid or query references non-existent column.
  • Empty result: WHERE clause found no matches. Verify condition syntax.
  • Column A instead of names: QUERY uses column letters (A, B, C) when data has headers, or Col1, Col2 with IMPORTRANGE.
  • Type mismatch: mixing numbers and text in one column breaks QUERY. Clean data first.

QUERY vs FILTER vs Pivot Table

  • QUERY: single formula, SQL-like, most powerful. Best for complex filters and aggregations.
  • FILTER: simpler syntax, returns matching rows only. No aggregation.
  • Pivot Table: point-and-click, interactive. Best for exploration and dashboards.

Common Google Sheets mistakes to avoid

Even experienced users hit the same pitfalls with Sheets formulas and shared spreadsheets. Being aware of these traps saves hours of debugging and rework.

  • Not checking sharing permissions before sending. A file shared with “Anyone with the link” behaves differently from “Restricted.” Always verify who can access before you share externally.
  • Working on a shared file without version history awareness. Google Workspace keeps version history, but collaborators can overwrite your work. Use File > Version history > See version history to review changes.
  • Ignoring the auto-save indicator. The “All changes saved in Drive” indicator confirms your work is persisted. If it says “Saving…” for too long, your connection may be unstable.
  • Forgetting to check on mobile. Some formatting and features render differently on the Google Workspace mobile apps. Test on your phone before sending important content.
  • Not using keyboard shortcuts. Google Workspace has extensive shortcuts (press Ctrl+/ or Cmd+/ to see them all). Learning the top 5-10 shortcuts saves significant time.

Power-user tips for Google Sheets

Once the basics are solid, these techniques let you work faster and with more control.

  • Use templates as starting points. Google Workspace includes free templates for common documents. Access via File > New > From template gallery. Customize once, reuse forever.
  • Master search operators inside Drive. Search operators like type:document, owner:me, and before:2025-01-01 narrow results dramatically. Combine multiple operators for precise filters.
  • Use offline mode when your connection is unreliable. Enable offline access in Drive settings so you can keep working during network outages. Changes sync automatically when you reconnect.
  • Set up Google Workspace apps on desktop. Drive for Desktop syncs files to your local machine and integrates with File Explorer or Finder. Works better than the web interface for large files.
  • Bookmark important documents. Star files in Drive to see them at the top of your Home view. Great for daily reference documents.

Real-world workflow examples

Concrete scenarios where these features solve everyday problems:

For students and BSIT capstone teams: Use shared Google Docs for capstone documentation, with real-time collaboration replacing back-and-forth email attachments. Version history preserves an audit trail of who wrote what.

For freelancers and consultants: Combine Google Drive folders (per client) with shared permissions for smooth handoffs. Clients can view or comment without needing separate accounts.

For small teams: A shared Drive folder plus a linked Google Sheet as project tracker gives structured collaboration without paying for enterprise tools.

Best practices summary

The pattern that works across nearly every Google Workspace use case:

  • Start simple, add complexity when needed. A basic Doc or Sheet solves 90 percent of cases. Only add scripts, add-ons, or complex formulas when the simple version breaks.
  • Version history is your safety net. Every serious edit should be reversible via File > Version history.
  • Share thoughtfully. Restricted sharing beats Anyone-with-link for anything sensitive. Add specific emails for tighter control.
  • Mobile-check before sending. A quick preview on your phone catches layout issues that never show up on desktop.
  • Learn keyboard shortcuts. The top 10 shortcuts save 30 minutes a week if you use Workspace daily.

Recommended Google Sheets resources

The links below are affiliate links. We may earn a commission at no extra cost to you when you buy or sign up. See our affiliate disclosure.

Frequently Asked Questions

Is QUERY the same as SQL?

QUERY uses Google Visualization API Query Language, which is SQL-inspired but not full SQL. Most SELECT, WHERE, GROUP BY, ORDER BY patterns work. Joins and subqueries are not supported.

Does Excel have QUERY function?

No. QUERY is Google Sheets exclusive. Excel users can use Power Query (a separate tool) or Excel’s FILTER + SORTBY + UNIQUE combinations for similar effect.

How do I use QUERY with dates?

Use date 'yyyy-mm-dd' format inside quotes: WHERE B > date '2026-01-01'. For cell references: WHERE B > date '"&TEXT(F1,"yyyy-mm-dd")&"'

Can QUERY do joins across sheets?

Not directly. Use VLOOKUP to enrich data first, then QUERY the result. Or wrap two IMPORTRANGE-based QUERY calls together with helper columns.

Why does QUERY return “Query completed with an empty output”?

No rows matched your WHERE clause. Check filter conditions, data types (dates need date ‘…’ wrapping), and text case sensitivity.

Adrian Mercurio

Full-Stack Developer at PIES IT Solution

Specializes in building complete capstone projects with full documentation. Strong background in PHP/MySQL development and database design. Has personally built and tested over 30 capstone-ready projects with ER diagrams, DFDs, and chapter-by-chapter thesis documentation.

Expertise: PHP  ·  Laravel  ·  Database Design  ·  Capstone Projects  ·  C#  ·  C  · View all posts by Adrian Mercurio →

Leave a Comment