Well, I’m a newbie too, I’m not a coder or similar. Not my ground. I started to learn some dataview (only simple dql, because I don’t know JS) with the practice and applying some logical deductions.
The first line - TABLE, LIST, TASK - is about the output: what you want to see after your fetching/filtering your pages in commands bellow (FROM, WHERE, SORT, etc.). In Tables you need to define your columns; in Lists you can add some extra information (fields values or your own text); in Tasks you can’t ‘edit’ the output.
Taking tables as example.
The main work of the query is defined in the commands bellow.
-
FROM fetch your source by pages, tags, inlinks, outlinks, file, … This is important also for performances issues because the other conditions/filters (where…) are applied only to the pages defined in FROM. If no source, dataview need to work more, applying the filters to ALL your notes in vault. For large vaults this could be a problem.
-
WHERE works as a filter by defined conditions.
-
FLATTEN. You can apply flatten before WHERE (or without where and from). But this command is more complicated to explain. For moments forget your subtag query. Think in a field with multiple values (an array). For example:
field:
- value 1
- value 2
If you create a table with field, for each page you have a list of values in same row. Flatten allows you to separate the field values per row. As consequence, follow the example, you see two rows: each one with the (repeated) file.link and one field value, i.e., not one but two rows in your table.
In doing this, you can define a new name for this flatten values: FLATTEN field AS "name". And this is the name you can use in the output (first line of table query).
Usually this is used for multiple values in field that need to be separated by singular values. And sometimes we need to use group by after to avoid some repetitions or to group results with same value in on field (as you probably want to do with all the notes with the same status).
(I’m lost, I can’t - and I don’t know - explain ALL the valences of this command).
Returning to your query, we do this “renaming” in flatten because is the only way to define a new name avoiding the repetition in SORT for all the expression string(map(.....
And this flattening has no other consequences for the query (because you have only one value in status).
-
SORT - Only after this steps you can sort the results: because only now you have the fields/values filtering and the “new” name.
This is a rude synthesis because it’s possible to use multiple “flatten”, “group by” and “sort”… but with the premisse that commands are executed in order.