# Ad Hoc Query

> A quick, one-time question to the data. You write it on the spot.

**Field:** Data Engineering  
**Category:** Analytics & BI  
**Also known as:** Ad-Hoc Query, Ad Hoc Analysis, One-Off Query

## Think of it like

It is like asking a quick question in class. You need the answer now, just this once.

## Definition

An ad hoc query is a one-time question asked of the data, written on the spot. It is not part of a saved report or a dashboard. An analyst usually writes it in SQL against the warehouse. If the same question keeps coming back, it is turned into a saved report. Most warehouses are built so these quick questions run fast.

## Example

The boss asks why refunds jumped this week. Jack writes a quick query, finds one country behind it and sends the answer in ten minutes.

## Example code

```sql
SELECT country, COUNT(*) AS refunds
FROM orders
WHERE status = 'refunded'
  AND order_date >= DATE '2026-11-01'
GROUP BY country
ORDER BY refunds DESC;
```

A quick question: which countries had the most refunds this month?

## Why it matters

Real questions rarely fit a dashboard made last year. Quick queries handle the surprises.

## Common mistake

Answering the same question by hand every week. After the third time, save it as a report.

## Three principles

- **One time.** Asked once, for a reason today.
- **Written on the spot.** Usually in SQL.
- **Repeats become reports.** Save what keeps coming back.

## Related terms

- [Structured Query Language (SQL)](https://learn.benibix.com/term/development/sql)
- [Database Query](https://learn.benibix.com/term/development/query)
- [Data Warehouse](https://learn.benibix.com/term/data/data-warehouse)
- [Dashboard](https://learn.benibix.com/term/data/dashboard)
- [DuckDB](https://learn.benibix.com/term/data/duckdb)

![Data flows left to right: an app database and files are loaded into a data warehouse, a semantic layer sits on top of it, and BI tools read from that layer. The tools serve three uses: a dashboard, a quick ad hoc query and a self-service chart that a business user builds alone.](https://learn.benibix.com/diagrams/bi-flow.svg)

---

Source: https://learn.benibix.com/term/data/ad-hoc-query
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
