Dataview queries from internal links

What I’m trying to do

As far as I can tell, the from statement in Dataview accepts only folder paths and tags. However, this is not how I have organized my vault, I use internal links.

For example, say I have a fiction book that I’m reading - Harry Potter. All my notes are under the root folder. However, the Harry Note has an internal link, that links it to [[Fiction Book]], where the [[Fiction Book]] file is an MOC.

Now I can visualize this relationship in the graph view, however I have frontmatter, that I also want to query and show alongside, allowing me to view, for example, the date I finished the book, or the rating I have given it.

Things I have tried

I did try to reorganize my entire vault by adding tags wherever possible, however I feel like this goes against the the natural way I use Obsidian.

I am terribly sorry if there a simple way to tackle this, however I just can’t seem to find the solution. Thank you!

You are right, the FROM statement is especially for limiting the number of queried files to certain folders or tags.

The actual query, however, is done via the WHERE conditions.

Let’s say the frontmatter of your “Harry” note looks like this:

title: Harry Potter and the Philosopher's Stone
date-finished: 2023-03-29
rating: 5
genre: fiction

Then, in your “Fiction Book” note, you could add the following dataview query:

TABLE WITHOUT ID link(,title) AS Title, date-finished AS Finished, rating AS Rating
FROM [[]]
WHERE contains(genre,"fiction")
SORT rating DESC

The FROM [[]] means that you only query files that have a link to your current note (in this case, the FICTION BOOK note). If you want to query all notes from your vault, write FROM "".

Is this what you want?


My understanding is that FROM sources can query links, files, folders, and tags.

Something along the lines of:

FROM outgoing([[Harry Potter]])

1 Like

Yes. But if you want to search for other metadata (like ratings etc.), you have to define this search after the WHERE statement.

You can do simple searches with FROM, for example: FROM "a subfolder" just means: list all the files from this subfolder. However, if you want to tell dataview: “List all files from my vault that belong to the ‘fiction’ genre”, you have to use WHERE.

Your example query (FROM outgoing([[Harry Potter]]) will list all files that are linked from the Harry Potter note. Maybe I haven’t completely understood what kind of query you want to do - is your problem solved with my above solution?

Edit: I just realized now that the above reply wasn’t from the OP… :wink: Anyway, so this post could be seen as a further refinement of @eightning 's reply! :slightly_smiling_face:

Oh yes this is exactly what I needed. Thanks everyone!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.