# Queries

Keep a list of matching notes inside a note. Results update as your files change.
Use the same words, tags and properties as [search](/docs/search).

## Add a query

````md
```query
#travel kyoto
```
````

A `query` block lists the notes and files that match a [search](/docs/search),
the same words and `#tags` you type in the search box. Click a result to open
it. The list leaves out the note that holds the block, which always matches
its own words. Shared links show the block as code.

````md
```query sort=due show=due,priority view=table limit=20
[status:todo] #work
```
````

A block can filter by [property](/docs/search#search-by-property), and takes
options after the word `query`:

| Option    | Does                                                                        |
| --------- | --------------------------------------------------------------------------- |
| `sort`    | Orders by a property, or by `name`, `updated` or `created`. `-due` reverses |
| `show`    | Shows up to 8 properties on each result                                     |
| `view`    | `table` gives each `show` property a column. `list` is the default          |
| `limit`   | Shows at most this many results, up to 100                                  |
| `group`   | Gathers the results under each value of a property                          |
| `flatten` | Gives each item of a list property its own row                              |
| `count`   | With `group`, shows one row per value and how many notes hold it            |
| `sum`     | With `group`, adds up a number property per value                           |
| `avg`     | With `group`, averages a number property per value                          |

## Group results

````md
```query group=status sort=due
#work
```
````

`group` puts the results under a heading per value, with the notes that lack
the property last. A note whose property is a list appears under each item. A
heading counts every match, so `2 of 7` means the block shows 2 of the 7 notes
with that value; raise `limit` to see more.

## Summarize a property

````md
```query group=author count sum=pages sort=-pages
#book
```
````

Add `count`, `sum` or `avg` to a grouped block and it turns into a summary:
one row per value, no notes. `sort` then takes `count` or a property named in
`sum` or `avg`, and `limit` caps the rows. Only numbers count toward a sum or
an average. `sum` and `avg` together name at most 4 properties.

## One row per list item

````md
```query flatten=authors sort=authors view=table
#book
```
````

`flatten` splits a note with `authors: [Le Guin, Chiang]` into two rows, one
per author. Sort by the same property to order the rows by item.
