> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stockful.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> The full set of StockfulQL clauses and the order they appear in a query

A StockfulQL query is built from **clauses**. Every query needs two: `FROM`, which chooses the dataset, and `SHOW`, which lists the metrics to return. Every other clause is optional and shapes the result.

## Anatomy of a query

The smallest useful query is a dataset and a metric:

```sql theme={null}
FROM inventory
  SHOW inventory_value
```

From there you add clauses to filter, group, set a date range, sort and chart. They always appear in a fixed order, and the report editor writes them in that order for you, so you rarely type a whole query by hand:

```sql theme={null}
FROM sales
  SHOW total_revenue AS "Revenue", units_sold
  WHERE vendor = 'Nike'
  GROUP BY ONLY TOP 5 product_type
  DURING last_month
  COMPARE TO previous_period
  HAVING total_revenue > 500
  ORDER BY total_revenue DESC
  LIMIT 10
  WITH TOTALS
  VISUALIZE total_revenue TYPE bar
```

## Clauses

| Clause                                                          | Required | What it does                                          |
| --------------------------------------------------------------- | -------- | ----------------------------------------------------- |
| [FROM](/stockfulql/syntax/from-and-show)                        | Yes      | Chooses the dataset (or combines two with `+`)        |
| [SHOW](/stockfulql/syntax/from-and-show)                        | Yes      | Lists the metrics and computed columns to display     |
| [WHERE](/stockfulql/syntax/where)                               | Optional | Filters rows before they are grouped                  |
| [GROUP BY](/stockfulql/syntax/group-by)                         | Optional | Groups rows by one or more dimensions                 |
| [TIMESERIES](/stockfulql/syntax/timeseries)                     | Optional | Buckets the results into day, week or month over time |
| [DURING / SINCE / UNTIL](/stockfulql/syntax/since-until-during) | Optional | Sets the date range (defaults to all your history)    |
| [COMPARE TO](/stockfulql/syntax/compare-to)                     | Optional | Compares the range against a prior period             |
| [HAVING](/stockfulql/syntax/having)                             | Optional | Filters groups by their aggregated metrics            |
| [ORDER BY](/stockfulql/syntax/order-by)                         | Optional | Sorts the results                                     |
| [LIMIT](/stockfulql/syntax/limit)                               | Optional | Caps the number of rows returned                      |
| [WITH](/stockfulql/syntax/with)                                 | Optional | Adds result modifiers like totals or percent change   |
| [VISUALIZE](/stockfulql/syntax/visualize)                       | Optional | Chooses the chart type and the metric it plots        |
| [ANNOTATE](/stockfulql/syntax/annotate)                         | Optional | Overlays domain events on a timeseries chart          |

With no `VISUALIZE` line the query renders as a table, which is the default. Leaving out the date clause reads all of your history.
