I made a Simple Query as follows:
{{query (and "#about-today" (between [[2023-07-03 Monday]] [[2023-07-02 Sunday]]))}}
It’s supposed to get all blocks in Journal with the tag #about-today between specified dates. The query works as it is, but the sorting of the blocks is from the most recent to the oldest. I would prefer this sorting to be from oldest to newest. Table view doesn’t help because I don’t see the sub-blocks. I don’t see a way to achieve what I need with a Simple Query and I would appreciate some help making an advanced query for it.
Well… It’s not going to work without losing your group by page property.
When we add it back in
Here’s the query:
#+BEGIN_QUERY
{:title [:h3 "About Today"]
:query [:find (pull ?b [*])
:in $ ?page ?start ?end
:where
[?r :block/name ?page]
[?b :block/refs ?r]
[?b :block/page ?p]
[?p :block/journal-day ?d]
[(>= ?d ?start)]
[(<= ?d ?end)]
]
:result-transform (fn [result] (sort-by (fn [r] (get-in r [:block/page :block/journal-day])) result ))
:group-by-page? false
:inputs ["about-today" 20230630 20230703]
}
#+END_QUERY
Thank you very much for the solution! This query will help me do a weekly review by seeing the highlights of each day, so it’s very useful to me.
Thanks for this. I’ve been trying to do something along these lines, and I think from your responses @Siferiax what I want to do isn’t possible.
I like to use future journal pages to show my future diary. At the moment I use the Drafts App to run a script which looks for journal pages and writes to a single “future journal” page with page embeds for any future journals. It works fine, but I want to move away from using external scripts to update LogSeq.
I can use a query for an equivalent of the page embed, but in descending order. From your comments, I’m taking it that it isn’t possible to use a query to group by page and have the pages in ascending order?
If that isn’t possible, then something like the query above would work for me, but what I’d need is to sort the blocks by the page they come from but also preserve the order they are on the page. For me, the query above doesn’t always keep the block order from the page.
Unfortunately that is correct.
I believe there is a feature request about keeping blocks in the order as they are on the page.
Thanks @Siferiax. For now, I’ve got it working by indenting any content on future journals pages.