Dataview: list notes from folder without categories (2-level backlinks) - subquery or join?

Hi, I’m trying to list notes from folder without second level backlinks (“categories”).

I think I need something like “subquery” or “SQL like join” in DataView.

My structure notes (connected by links) in folder: Root note → category notes (every category links to Root) → notes in categories (every note links to category note). And “orphan” notes (without link to category) in the same folder.

I can list tree (notes in categories) in Root like that:

- Animals
	- Cat
	- Dog
	- Chicken
- Food
	- Tomato
	- Chicken

It works:

dataview
list file.inlinks from [[]]

This is another way (but displays only notes in categories without title of categories):

dataview
list
where contains(this.file.inlinks, file.link)
flatten this.file.inlinks as L
group by L.file.inlinks

But now I want to list notes from folder which are not in any category (notes without links to “Animals” or “Food” for example).

I try this and this list notes not including categories:

dataview
list 
from "Folder"
where !contains(this.file.inlinks, file.link)
flatten this.file.inlinks as L
group by file.link

But I expect notes without categories. This is example expected result:

- Bus
- Train

Folder with example notes (queries in “Root” note):
Folder.zip (1.7 KB)

Summary

Orphan Notes

```dataview
LIST
FROM "Folder"
WHERE length(file.outlinks)= 0 AND length(file.inlinks) = 0 
```

Screenshots:

Part 1/2

Part 2/2

Thanks for reply.

It works with this simple example (when notes are empty). But it doesn’t work when notes contains link to any other note.

I need in WHERE clause specify only “categories” (backlinks to “Root” note), in this example: “Animals”, “Food”.

Pseudocode:

dataview
LIST
FROM "Folder"
WHERE "not contains link to any categories (backlinks to Root - `this`)"

I know I can get “categories” like that file.inlinks from [[]] or contains(this.file.inlinks, file.link), but I don’t know how to write first part “not contains link to selected notes”.

I consulted on Discord about my problem (thanks @Dovos): Discord

I was wrong approach. To archive my case (“categories”) I should use “inline metadata”: Metadata on Pages - Dataview

Instead of just links now I use Category:: [[Root]] for categories and In: [[Some category]] for notes in categories (look at doubled ::).

And now simply categories:

dataview
list
where category

tree (category-note):

dataview
list file.inlinks
where category

orphan notes:

dataview
list 
from "Folder"
where !category and !in

1 Like

Try the DQL02, which is based on your original input.

Summary

DQL02: get a note which is not refered exclduding the current file

```dataview
LIST
FROM "Folder"
WHERE file.name != this.file.name
WHERE (
        none(file.outlinks, (o) => contains(o, this.file.link)) AND 
        none(file.outlinks, (o) => contains(o.file.outlinks, this.file.link))
	   ) 
      OR (length(file.outlinks)= 0 AND length(file.inlinks) = 0)
```

Screenshots:

Part 1/3: Add [[Bus]] in the [[Bus]] file.

Part 2/3

Part 3/3

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