Query question - return all pages which reference [[page1]] and [[page2]]

Hi folks, this seems like it should be a simple one but I’m struggling.

{{query (and “page1” “page2”)}}
query-properties:: [:page]
query-table:: true

returns a table of pages where [[page1]] and [[page2]] are mentioned in the same block.

{{query (and [[page1]] [[page2]])}}
query-properties:: [:page]
query-table:: true

returns the above, but with the addition of pages where [[page1]] is mentioned in a block nested under a block with mentions [[page2]] (or vice versa).

#+BEGIN_QUERY
{:query
 [:find (pull ?page [*])
  :in $ ?t1 ?t2
  :where
   ;; restrict to pages
   [?page :block/name]
   ;; first required page
   [?page :block/path-refs ?r1]
   [?r1 :block/name ?t1]
   ;; second required page
   [?page :block/path-refs ?r2]
   [?r2 :block/name ?t2]]
 :inputs ["page1" "page2"]}
#+END_QUERY

gives me no results (this query was written by an LLM, so it may be wrong in another way).

Anyone got any pointers?

The following lines of LLM’s code:

[?page :block/path-refs ?r1]
...
[?page :block/path-refs ?r2]

…are looking inside the path-refs of ?page itself. Should instead be some blocks of ?page:

[?b1 :block/page ?page]
[?b1 :block/path-refs ?r1]
...
[?b2 :block/page ?page]
[?b2 :block/path-refs ?r2]

Thanks @mentaloid!

Subbing in your suggestion gives me this:

#+BEGIN_QUERY
{:query
 [:find (pull ?page [*])
  :in $ ?t1 ?t2
  :where
   ;; restrict to pages
   [?page :block/name]
   ;; first required page
   [?b1 :block/page ?page]
   [?b1 :block/path-refs ?r1]
   [?r1 :block/name ?t1]
   ;; second required page
   [?b2 :block/page ?page]
   [?b2 :block/path-refs ?r2]
   [?r2 :block/name ?t2]]
 :inputs ["page1" "page2"]}
#+END_QUERY

which works! Thank you!

(I also got tripped up for a little while that the inputs need to be lower case, even if the page name is upper case…)