Dataview only displays entries that don't respect the condition

What I’m trying to do

Hi.

I’m new to obsidian and I would like to use the plugin Dataview.
However, I cannot seem to make queries work the way I want.

More specifically, they seem to display everything I did not ask them to display.

This seems to be a general problem, as I have tested it with several criteria and the results always seem “inverted”.

Here is a test environnement I created to test it out.

File structure

image

For this test, I would like Dataview to display a table in “Dataview overview test”, with a single line refering to “Data to display”.

To achieve this, I added the following lines at the top of the “Data to display” file.
I read that this creates metadata which I can look for in my overview file

First query

---
title: Test data
author: Cesar
content: data
---

I then tried to generate a view in the “Dataview overview test” using the following lines.

```dataview
TABLE author, title
FROM "Workspace"
WHERE content = data
```

However, here is the result I get
image

I’m confused because it did not detect the tag I added in “Data to display”, but rather the tagless file that contains this query.

Second query

I also tried this code

```dataview
TABLE author, title
FROM "Workspace"
WHERE content != data
```

image

Which returned the view I want. However I feel like it sould not as I use != instead of =.

Is the second query the “normal” syntax for this tipe of request? It feels like a bug to me but has anyone else encountered this?

Sorry if this is a know issue/an error on my part/not the right forum. I tried solving this myself but could not as I’m pretty new to this.

When you do content = data you’re comparing the value of the fields content and data. Since the latter is not defined, and dataview is generous enough to not give you an error message, you’ll get all the files where content = null. Similar logic applies the other way around, when you’re doing content != data (and would also apply if you didn’t define content)

So to check for the value of content to be equal to something, you’ll need to do WHERE content = "data" in your query. And if you want to ensure that there actually is a content field, you could extend it to WHERE content AND content = "data".

Finally, the checks above are checking against the entire value of content, and if you want to check against just parts of it, you’d need to do something like: WHERE content AND contains(content, "at") or similar. See also Object, arrays and string operations

1 Like

Thanks for your amazing answer. It worked perfectly.
I had heard about the contains function but wanted to use a simple mock example before thinking about it. However it now seems self-explanatory so I should be fine.
I’m quite rusty with SQL and other syntaxes so I really appreciate the explanation of the technical differences between what I did, your solution and why it displays a table despite the missing field.
Have a great day, and thanks again !

1 Like

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