Dataview makes it possible to write SQL-like queries against your notes.

Quick Reference

Fields

Fields can be selected for a Dataview table. Fields come from

  • YAML frontmatter (content fenced with ---)
  • Inline fields (in-note content prefaced with <field-name>:: )
  • Implicit

Implicit Fields

  • file.name: The file title (a string).
  • file.folder: The path of the folder this file belongs to.
  • file.path: The full file path (a string).
  • file.link: A link to the file (a link).
  • file.size: The size (in bytes) of the file (a number).
  • file.ctime: The date that the file was created (a date + time).
  • file.cday: The date that the file was created (just a date).
  • file.mtime: The date that the file was last modified (a date + time).
  • file.mday: The date that the file was last modified (just a date).
  • file.tags: An array of all tags in the note. Subtags are broken down by each level, so #Tag/1/A will be stored in the array as [#Tag, #Tag/1, #Tag/1/A].
  • file.etags: An array of all explicit tags in the note; unlike file.tags, does not include subtags.
  • file.inlinks: An array of all incoming links to this file.
  • file.outlinks: An array of all outgoing links from this file.
  • file.aliases: An array of all aliases for the note.

Queries

You can write queries in the query language (SQL-like) or using the Javascript API.

Query Language

```Dataview
TABLE|LIST|TASK <field> [AS "Column Name"], <field>, ..., <field> FROM <source> (like #tag or "folder")
WITHOUT ID (to remove the automatic link field)
WHERE <expression> (like 'field = value')
SORT <expression> [ASC/DESC] (like 'field ASC')
GROUP BY <field>|(<computed-field) AS name
FLATTEN <field>|(<computed-field) AS name
```

Notes

  • The file field is included by default when using the query language. It’s not currently possible to change its default name from “File.”
  • Tables are currently required to have at least single field
  • Refer to fields with spaces by using a hyphen (-). Punctuation is removed and capitals are made lower case . (e.g. a field Hello world! becomes hello-world)
  • You can use Boolean operators and and or to use multiple sources. You can even mix tags, folders, and links in these FROM statements

Javascript API

```dataviewjs
dv.table(["File", "Genre", "Time Read", "Rating"], dv.pages("#book")
  .sort(b => b.rating)
  .map(b => [b.file.link, b.genre, b["time-read"], b.rating]))
```

Reference: Codeblock Reference

Links