This cheatsheet provides a handy reference guide for writing queries using Dataview Query Language (DQL) in the dataview plugin for Obsidian.md note-taking app.
Use it however you like but I would suggest you copy this file and simply paste it into your own Obsidian vault. You can then reference this from within your own vault by either accessing the file or searching in your vault for specific command.
Star and follow this repository if you want to be updated when I add more examples to this list.
- LIST
- Data Commands
- Meta Data Examples
LIST FROM <tag-name>
Example
LIST
FROM
#games
TABLE
Title
FROM
#tagName
- FROM
- WHERE
- SORT (to do)
- GROUP BY (to do)
- FLATTEN
- LIMIT
Selecting from different sources such as;
FROM #tag
Example
TABLE
file.cday as "Created Date"
FROM
#my-tag
!#tag-name
Example
TABLE
Title,
Rating,
Seen,
SeenDate as "Seen on"
FROM
#movie AND !#template
The above example will return all notes with a tag #movie
but exclude notes with a tag #template
. This is handy if you have a note with pre-populated tags but it's only used as a template so you don't want to see it in your table view.
FROM #tag AND !"FolderName"
Example
TABLE
Title,
Rating,
Seen,
SeenDate as "Seen on"
FROM
#movie AND !"TemplatesFolder"
By including !"FolderName"
we specify that we do not want to return any matches if the are located in the specified folder.
FROM "folder-name"
Example
TABLE
file.cday as "Created Date"
FROM
"my-folder-name"
FROM "path/to/file-name"
Example
TABLE
file.cday as "Created Date"
FROM
"TopFolder/SubFolder/my-file-name"
GROUP BY <property-name>
Examples
TABLE
rows.file.name as "File"
WHERE category
GROUP BY category
LIST
rows.file.name
WHERE
category = "first-category"
GROUP BY category
NOTE: When using group by, the structure of the results changes. Instead of directly accessing file.name
, you must use the rows
property to access the file properties within each group. This is because results are now grouped into rows based on the group by field.
Examples of queries containing WHERE clause.
WHERE <property-name>
Example
TABLE
file.cday as "Created",
Category
FROM
#books
SORT
file.cday
WHERE
Category
The above example ensures to show only results where the meta-data 'Category' is not empty.
WHERE <string-property-name> = "my-value"
WHERE <digit-property-name> = 123
Examples
LIST
WHERE
Category = "my-value"
LIST
WHERE
DigitProperty = 123
FLATTEN <property-name>
Code example:
TABLE
Title,
Action
FLATTEN Action
Result example:
File Name | Created | Action |
---|---|---|
Note 1 | July | Action name 1 |
Note 1 | July | Action name 2 |
Note 2 | August | My Action 123 |
Note 2 | August | Hello World |
Snippet
CHOICE(<bool-property>, "Yes", "No") as "custom-name"
Example
TABLE
Author as "Author",
choice(read, "Yes", "No") as "Read",
FROM
"Books"
LIMIT 10
Example:
TABLE
Title,
Rating
WHERE
Rating > 3
LIMIT 10
Obsidian allows YAML and JSON for metadata.
JSON
{
"Author": "Author Name",
"Genre": "Fiction",
"DateRead": "2022-06-01",
"Read": false,
"Tags": [
"Mind-blowing",
"Interesting",
"Science"
]
}
YAML
Author: Author Name
Genre: Fiction
DateRead: '2022-06-01'
Read: false
Tags:
- Mind-blowing
- Interesting
- Science