Querying with NOT (not included in, non existent, not equal...)

I’m trying to find out how I can:

  1. Find pages without certain property
  2. Find pages where certain property is different from X
  3. Find pages where that has certain property equal to X but another property different from Y
    and so on.

So basically all kinds of negation.

I was trying to use simple (not … ) but didn’t work.

Like this to find thing that don’t have property class.

{{query (not (property class))}}

Then I tried the complex version, like this, to find what has class different than “Question”:

LATER #+BEGIN_QUERY
{
 :query [:find (pull ?b [*])
		:where          
			[property ?b :class ?q]
                        (not ?q "Question")		
		]
}
#+END_QUERY

I’m clearly missing how this query works.

How to find things that don’t have a property?
And a property different from a value?

I also wrote “question” and “Question” in the property class.
Is there a way to make it case insensitive?

1 Like

I’m trying to figure out the same thing, specifically how to query for pages that don’t have an “archived” property. I’m trying to set up the PARA method. Did you make any progress on this?

  • The OP is very broad.
  • For pages not having an archived property, try this:
    #+BEGIN_QUERY
    {
      :query [:find (pull ?b [*])
        :where
        [?b :block/name]
        [?b :block/properties ?props]
        (not [(get ?props :archived)])
      ]
    }
    #+END_QUERY
    
    It may return too many pages, so consider further narrowing it.