Blocks with only 1 tag

hi,

so far, i tried this, but no work …

#+BEGIN_QUERY
{:title "Blocks with Only One Tag"
 :query [:find (pull ?b [*])
         :where
         [?b :block/tags ?tag]
         [(count ?tag) 1]]}
#+END_QUERY

after some search, i didn’t find any solution

thank you for any hints

  • This should work for pages:
    #+BEGIN_QUERY
    {:title "Pages with Only One Tag"
     :query [:find (pull ?p [*])
         :where
             [?p :block/tags ?tag1]
             (not
                 [?p :block/tags ?tag2]
                 [(not= ?tag1 ?tag2)]
             )
     ]
    }
    #+END_QUERY
    
  • This should work for all blocks:
    #+BEGIN_QUERY
    {:title "Blocks with Only One Tag"
     :query [:find (pull ?b [*])
         :where
             [?b :block/properties ?props]
             [(get ?props :tags) ?tags]
             [(count ?tags) ?count]
             [(= ?count 1)]
     ]
    }
    #+END_QUERY
    
2 Likes

hi,

thank you very much.

regarding the code for blocks, the code is looking for properties ?

[?b :block/properties ?props]

sorry, i mean query in journals, where the blocks with only one tage

thank you again

  • Tags are special built-in properties.
    • Therefore, to look for the number of tags, we have to look in the properties.
  • To limit the blocks to those in journals, add these lines:
             [?b :block/page ?p]
             [?p :block/journal-day]
    
1 Like