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

# Overview

> The clauses a QueryfulQL query is built from, and the order they go in.

A QueryfulQL 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.

QueryfulQL follows ShopifyQL, so a query written for Shopify's analytics usually runs here unchanged.

## Anatomy of a query

The smallest useful query is a dataset and a metric:

```sql theme={null}
FROM sales
  SHOW net_sales
```

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

```sql theme={null}
FROM sales
  SHOW net_sales AS "Net sales", orders
  WHERE sales_channel = 'Online Store'
  GROUP BY TOP 5 product_vendor
  DURING last_month
  COMPARE TO previous_period
  HAVING net_sales > 500
  ORDER BY net_sales DESC
  LIMIT 10
  WITH TOTALS, PERCENT_CHANGE
  VISUALIZE net_sales TYPE horizontal_bar
```

## Clauses

| Clause | Required | What it does |
| - | - | - |
| [FROM](https://docs.queryful.app/queryfulql/syntax/from-and-show.md) | Yes | Chooses the dataset, or combines several |
| [SHOW](https://docs.queryful.app/queryfulql/syntax/from-and-show.md) | Yes | Lists the metrics and calculated columns |
| [WHERE](https://docs.queryful.app/queryfulql/syntax/where.md) | No | Keeps only the rows that match, before grouping |
| [GROUP BY](https://docs.queryful.app/queryfulql/syntax/group-by.md) | No | Breaks the results down by one or more dimensions |
| [TIMESERIES](https://docs.queryful.app/queryfulql/syntax/timeseries.md) | No | Splits the results by day, week or month |
| [SINCE, UNTIL, DURING](https://docs.queryful.app/queryfulql/syntax/since-until-during.md) | No | Sets the date range. Left out, the report covers all your history |
| [COMPARE TO](https://docs.queryful.app/queryfulql/syntax/compare-to.md) | No | Compares the range with an earlier one |
| [HAVING](https://docs.queryful.app/queryfulql/syntax/having.md) | No | Keeps only the groups whose totals match |
| [ORDER BY](https://docs.queryful.app/queryfulql/syntax/order-by.md) | No | Sorts the results |
| [LIMIT](https://docs.queryful.app/queryfulql/syntax/limit.md) | No | Caps the number of rows |
| [WITH](https://docs.queryful.app/queryfulql/syntax/with.md) | No | Adds totals, percent change, running totals or another currency |
| [VISUALIZE](https://docs.queryful.app/queryfulql/syntax/visualize.md) | No | Chooses the chart and the metrics it plots |

Without `VISUALIZE` the report is a table. Fields of related records, like the customer behind an order, are written with a dot: see [Linked records](https://docs.queryful.app/queryfulql/syntax/linked-records.md).

## Writing it

* Keywords can be upper or lower case. Field names are lower case, with underscores.
* Text values go in single quotes: `'Online Store'`.
* Each clause usually starts a new line, but doesn't have to.
* Every dataset's page lists the metrics, dimensions and filters it has. Start at [Datasets](https://docs.queryful.app/queryfulql/datasets/overview.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.