Advance Query - Query two different tags in the same page

I am still getting my head around datalog and datomic, but I have been trying to query pages that have two tags occuring in themsimultaneously, from the advanced example project example:

 #+BEGIN_QUERY
{:title "All todos with tag project"
 :query [:find (pull ?b [*])
       :where
       [?p :block/name "project"]
       [?b :block/ref-pages ?p]]}
#+END_QUERY

However, while I can get an or clause to work, using an and clause does not find pages with both tags in them. I am assuming I am misunderstanding something obvious about the syntax, but could use some help. So, the following does not work:

#+BEGIN_QUERY
{:title "All todos with tag project"
 :query [:find (pull ?b [*])
       :where
       (and 
       [?p :block/name "2021w34"]
        [?p :block/name "prm"]
       )
       [?b :block/ref-pages ?p]]}
#+END_QUERY

I could use a little help to fix this up and understand (more to the point) why an OR works here but not the AND (and basically, how to query two different tags occuring in the same page.

merci!
Daryl,.

1 Like

try this query

#+BEGIN_QUERY
{:title "All todos with tag project"
 :query  [:find (pull ?b [*])
     :where
     [?b :block/path-refs [:block/name "2021w34"]]
     [?b :block/path-refs [:block/name "prm"]]
    ]}
#+END_QUERY
1 Like

@Darwis

This works great. This definitely works if I have everything in Tags: on a page. Thank you so much.

ie. Tags: prm, neo, 2021w40

(out of curiosity, is there a way to make it work if, for example if I had Tags: separate from a line called Ping: in a form like
Tags: prm, neo
Ping: 2021w40
This is what I was trying to solve for originally, though your answer works great if I just place the week component under Tags as well. ).

ciao!
Daryl.