Logseq Simple Queries - All the basics to filter what you need
Summary
TLDRThis video script from 'Tools on Tech' offers a comprehensive guide to constructing queries in Logseq, a knowledge management tool. It covers the basics of query building, the use of operators and functions, and how to filter tasks with tags and priorities. The tutorial also explores advanced features like properties for tasks and pages, which allow for dynamic and organized data retrieval. The script emphasizes the importance of understanding the underlying structure of queries for effective use of the tool.
Takeaways
- ๐ The video aims to simplify the process of building queries in Logseq, focusing on the basics to help users extract the most out of their data.
- ๐ The core layout of a query in Logseq is the use of curly brackets with 'query' in the center, which Logseq can auto-generate for the user.
- ๐ Understanding how operators and functions work within queries is fundamental, with functions followed by values inside the brackets.
- ๐ The query builder in Logseq is a helpful tool for constructing queries, but it's also crucial to understand the underlying code for more complex setups.
- ๐ The importance of correct bracket placement in queries is emphasized, as errors often arise from misplaced or missing brackets.
- ๐ท Filtering for specific tags is a key feature in Logseq, allowing users to organize their tasks by context, such as 'at home' or 'at work'.
- ๐ The 'and' operator is highlighted as a core element in building queries, combining multiple conditions to filter results accurately.
- ๐ The video demonstrates how to dynamically update queries by adjusting tags and priorities, showing the flexibility of Logseq's query system.
- ๐ The 'between' property is introduced for filtering tasks based on specific date ranges, useful for reviewing past or planning future tasks.
- ๐ Properties are a powerful feature in Logseq for categorizing and filtering tasks, as shown with the 'system' property for gaming consoles.
- ๐ Page properties are discussed as a way to track information over time, such as work hours, and can be used to create overviews and summaries.
Q & A
What is the basic structure of a query in Logseq?
-The basic structure of a query in Logseq is a pair of curly brackets with the keyword 'query' inside. This is the core layout that is always needed for any query.
How does Logseq handle operators and functions within queries?
-In Logseq, operators and functions are used within queries by placing them between the curly brackets. The function is followed by values, and it's important to understand that Logseq does not use traditional arithmetic operators like '+' for calculations.
What is the purpose of the query builder in Logseq?
-The query builder in Logseq helps users construct queries by suggesting functions and values. It can auto-generate parts of the query and helps in avoiding syntax errors related to the placement of brackets.
How can you filter tasks by tags in Logseq queries?
-You can filter tasks by tags in Logseq by using the 'tag' function within a query. For example, to filter tasks tagged with 'home', you would use 'tag home' within your query.
What is the difference between 'and' and 'or' operators in Logseq queries?
-The 'and' operator in Logseq queries requires all conditions to be met for a result to be returned, while the 'or' operator allows for results to be returned if any of the conditions are met.
How can you filter tasks by priority in Logseq?
-You can filter tasks by priority in Logseq by using the 'priority' function followed by the desired priority level (A, B, or C) within your query.
What is a 'property' in Logseq and how is it used?
-A 'property' in Logseq is a custom attribute that can be added to blocks or pages to categorize and filter content. It is used within queries to filter results based on these attributes.
How can you use 'page properties' to track information over time in Logseq?
-You can use 'page properties' in Logseq to track information like work hours or book ratings over time. By adding these properties to journal entries or pages, you can create queries that filter and display this information in a structured way.
What is the 'not' operator used for in Logseq queries?
-The 'not' operator in Logseq queries is used to exclude certain results based on specified conditions. It is a negation operator that helps in removing items from the query results.
How can you use the 'between' function in Logseq queries to filter tasks by date?
-The 'between' function in Logseq queries allows you to filter tasks by a specific date range. You can specify two dates, and the query will return tasks that fall within that range.
What is the recommended approach when building complex queries in Logseq?
-When building complex queries in Logseq, it is recommended to limit the depth to around two layers (e.g., 'and' followed by multiple 'or' or 'not'). If the query becomes too complex, it might be better to use advanced queries or break it down into simpler parts.
Outlines
๐ Introduction to Query Building Basics
The speaker introduces the concept of query building in Lockseek, aiming to simplify the process of extracting data. They explain the basic structure of a query, emphasizing the use of curly brackets and functions. The importance of understanding operators and functions within queries is highlighted, with a practical example of filtering tasks based on their status. The Query Builder's utility in constructing queries is demonstrated, and the significance of correct bracket placement to avoid errors is stressed.
๐ Advanced Query Construction with Tags and Priorities
This paragraph delves into the use of tags for organizing tasks and the application of priorities to distinguish the importance of tasks. The speaker illustrates how to create a query to filter tasks by context, such as 'at home', and demonstrates the use of the 'and' operator to combine multiple criteria. They also discuss the limitations of the Query Builder and how manual adjustments can be made to refine query results, including the dynamic updating of queries as task properties change.
๐ Utilizing Dates with Between and Related Dates
The speaker explores the use of dates in queries to filter tasks based on when they are due or were completed. They explain the 'between' function, which allows for tasks to be retrieved within a specified date range, and note the limitations when using related dates directly in the Query Builder. Practical examples are given, such as creating a task for a specific date and then filtering tasks from a certain period, like the last seven days.
๐ฎ Properties for Enhanced Task Management
In this section, the speaker introduces the use of properties to add custom attributes to tasks, such as gaming systems (e.g., Xbox, PlayStation). They demonstrate how to filter tasks based on these properties and transform the query results into a table for better visualization. The flexibility of properties for sorting and filtering tasks is emphasized, along with the ability to refine lists by excluding certain properties.
๐ Page Properties for Tracking and Organization
The speaker discusses the use of page properties for tracking activities over time, such as work hours, and how they can be utilized within a journal for daily updates. They provide a step-by-step guide on creating a page property query and explain how these properties can be used to generate quick summaries of tracked data. The versatility of page properties for different types of pages is also highlighted, including their application in organizing books, projects, and other content.
๐ง Operators for Fine-Tuning Query Results
This paragraph focuses on the use of operators such as 'and', 'or', and 'not' to manipulate query results. The speaker explains how these operators can be used to combine or exclude criteria within a query. Practical examples are provided, such as creating a query for tasks that are high priority and not at home. The limitations of the Query Builder when using complex combinations of operators are acknowledged, and the speaker advises on best practices for constructing reliable queries.
Mindmap
Keywords
๐กQuery Builder
๐กBrackets
๐กFunctions
๐กTags
๐กAND Operator
๐กOR Operator
๐กNOT Operator
๐กProperties
๐กPage Properties
๐กBetween
๐กPriority
Highlights
Introduction to building queries in Lockseek with the basic structure of a query using curly brackets and the query function.
Explanation of operators and functions within queries, demonstrating the use of brackets, functions, and values.
The importance of understanding how calculations work differently in Lockseek compared to traditional arithmetic.
Demonstration of filtering tasks using functions and values, such as 'task' and 'to do later'.
Utilization of the Query Builder for constructing queries without memorizing syntax.
The significance of correctly placing brackets to avoid errors in query construction.
Using tags for organizing to-dos by context, such as location, demonstrated with a 'home' tag example.
Combining multiple criteria in queries using the 'and' operator to filter tasks by context and status.
Adjusting queries dynamically to include or exclude tasks based on their status, such as 'done'.
Introduction of the 'priority' feature to mark tasks with different levels of importance.
Building queries to filter tasks by priority, showcasing how to adjust and combine multiple criteria.
Using 'between' to filter tasks within a specific date range, with examples using journal dates.
The capability to use related dates in queries to dynamically show tasks from a certain time period.
Exploring 'properties' to add custom attributes to tasks, such as gaming systems (Xbox, PlayStation).
Transforming query results into a table format to view properties like gaming systems alongside tasks.
Using page properties to track information over time, such as work hours, within a journal.
Creating a timesheet summary page using page properties to quickly fill in work hours.
The power of using operators like 'and', 'or', and 'not' to manipulate query results based on conditions.
Practical examples of using 'not' to exclude certain tags from query results, like 'no filter'.
Strategies for building complex queries with multiple layers of conditions without breaking the query structure.
Emphasizing the importance of understanding the underlying code for debugging and building complex queries.
Transcripts
hey welcome to tools on Tech this week I
want to break down simple queries give
you all the building blocks you need in
about 10 minutes so you can build any
query you might need within lockseek and
get the most out of all that data you
were putting in there
now let's start with the absolute Basics
if you do slash query you get this the
life query Builder and if you click on
it you see that the core layout of a
query is just curly brackets with query
in the middle this you always need and
you don't really need to memorize
because loxiq will type it in for you if
you press slash query now the other core
element that you need to know is how
operators and functions work inside
queries let me quickly show you how that
looks you always have these brackets and
then there is a function basically and
then values
now looking at that that's a bit weird
because if we do calculations for
example you say one plus one equals two
and that's not how closure works I
explained that one in previous videos
but I'm going to recap it because it's
important Claudia would look at this
like this
and that would return to so that's a
little mind shift and in practice how
that looks is for example if you would
be filtering on tasks you say task which
is the function and then you say what
you would like to have so like for
example to do and later this is a core
element on how you build things within
simple query and we're going to dive
into that more once we get to operators
now one of the nice things that we have
the query Builder is while I'm going to
talk about the code bit a lot in this
video you can find a lot of things by
using the query Builder so for example
the one that I was showing you just now
is if I go to query
and then I would say click on the plus
find that task function that I just had
and do the same thing I say to do and
later
and click on the plus
then that would build the query for me
and now if I click on live query you
basically see a combination of the
things I just explained you see that we
have the query curly brackets that
surround it and we see one of these
functions tasked to do later in it so
this query just gets me all the tasks
that are in my system that are to do and
later now it's important to remember
that these brackets on the outside are
important a lot of times things go wrong
because the brackets are in the wrong
place for example you have brackets with
spaces in them or you have brackets
where you need them and you don't have
brackets where you don't need them so
for example if I would build a query I
would go like this
and I would forget the brackets so I do
something like this the task to do doing
I would get an error because now it's
not a function now it's looking actually
for specific things
now you can do something like aim for a
page so for example if I have like an
idea page
then that would work because I'm not
using a function I'm searching for
something like a reference inside my
table and this is also where things get
like a little bit confusing and I'll
dive into that when I talk references
and the and operator
so one of the bread and butter things
that you want to do with a query is
filter for specific tags and this is one
of the ways for example that I used to
order my to-do's I would tag something
with a location so let me give you there
a nice example say I have the trash that
needs to be put out so I'm making a
to-do and I'm saying like put out the
trash
and that's something that I need to do
at home so what do I do I add a tag and
I use from GTD the at symbol which means
that it's in a specific context and I
would say home
now this thing has a tag to it that says
at home meaning that if I'm at home I
can put out the trash
and then I can build a simple query that
would say hey I would like to get all
the results that I have
and I want to say all the things at home
I say page references and I say at home
and then it finds that to do so now I
have this at home query but it also
would show texts that have attacked with
that aren't tasks and that's the main
operator that I use with queries and
that is Task and I say like anything
that I need to do
and if I can click on the plus here then
it makes a more complex curvy and we're
gonna break this down to you understand
what's written here because the query
Builder will help you but understanding
what goes on on the water is why you are
here
so let's click on the live query and
look at that query build up
um so you look at the query and we're
gonna break it up so you have the outer
part which is the query itself and then
you see without a bracket around it the
reference towards home and that is
because it points towards a reference
and it's not a function and then after
it comes a function and that does start
with the brackets and it's a function
task which says like find me all the
tasks that are marked whatever I put
behind it so in this case just to do
what you could like do also to do doing
now later to make like a full list and
make sure everything gets captured and
then around that is another function
that's and and says all the things that
are in here have to be marked or else
we're not getting this setup so if we go
back and we look at the two lines that
we have then you see that I have this
one to do put out trash home and that
one matches because it is marked at home
and it's marked to do and then next one
that one gets filtered out because it's
marked with just the tag home but it's
not marked as it has to do if you would
go here and I would press Ctrl enter and
make it a to do
then you see that the query gets updated
and it returns but if it's not to do but
it's for example done
then it gets removed because we said we
only one tasks that are on to do
and then of course we can go here
and this is like one of the points where
the query Builder lacks right I can't
change it I have to either rebuild it so
in those cases I'm just going to go in
here and say like hey I would also say
like to see all the things that are done
to that now I've got both of them in my
view by doing a quick adjustment
[Music]
okay now let's dive into priority now I
put this list here of three things and
I'm going like okay these things are
important but some things are more
important than others so for example
feeding the cat well I won't be
forgetting that one because again
remember let's give that one a priority
by going give it Priority a you get
priority a b and c
and that puts like a nice marker in
front of it and say like hey this is
priority a then I can go to my query
that was already filtered for everything
at home and I said like hey I would like
to see just the things that are my
highest priority set so again I go to
plus I click priority I say a and I
click on plus again and it gets added
and now you see that I just get those
priority a markers
and if you look at the query Builder
there's not an extra ant that gets added
and there's like cumulative so you can
have multiple things in it so this one
says and and it says home tagged and
talk to do tagged and priority a text
those three things must match to get
like the result that we're having here
and that means that we only get one back
so for example if I say that putting out
the trash
is priority a then it will start popping
up the moment I save it as you see here
and if I say like oh no this is like
less priority I make it Priority B then
it will disappear again from List It
Takes a second and now it doesn't show
that one but I can go to things like my
query and say like hey I would like to
see priority A and B and if I do
something like that then they both show
up again now in practice of course you
might want to have a certain order in
this and one of the things that I do
with things like priority is that I take
a query like this and I say like hey I
would like to have everything in
priority a and I then just copy the
whole query put it under there
and give that one b
and now I have two queries and the top
query will tell me all my a priority
thing so it will be on top and the
second query will tell me my B
priorities which will be in the bottom
you could use Advanced queries and then
basically make a sorted list and make
sure that everything's like nice and
dandy and placed and in the right order
but this is just so much easier to set
up just make a couple of queries and put
them in the order that you want to see
those queries this is how I built my my
task list page where I just have a bunch
of queries in the order that I want to
scroll through them so first things that
come in there anything that I marked is
doing then I have like a b c's and then
all my other tasks are under it and then
I can just scroll through all the tasks
and pick a mix whenever I would like to
pick up this is much easier to build
than going straight into advanced
queries
now for the next one we're going to look
at between and between is a property
that gives you everything between a
certain date and that one's very much
based on Journal dates so if we adjust
our example here we should get nothing
because the to-do's that I made aren't
on my journal page they are on a sub
page so they don't have a date let's see
if that's the case I'm gonna go here I'm
gonna remove this last query
I'm gonna go to this top one
I'm also going to remove this priority
A1 let me use the query Builder I still
have to get used that I have this and
then I go to between
and I say you know you can pick a date
so I can say like hey I want something
that's between the first and the end of
March
now I have this setup and I get no
results of course I don't get any
results because I don't have any task in
March that is marked at home so let's go
to my journal page and make one so this
is the last day of March I say to do
March example and I would mark it as the
at home as we just did so now I made a
task in March and I made it on a
specific date and you'll see it pop
right back because the between is here
and it shows you where the task supposed
to be happening now I hear you asking
like this is nice but I'm not gonna
enter dates every time I want to build a
query for example to see what I needed
to do last week and that's totally fair
and that's why you can use like related
dates unfortunately you can't use them
in the query Builder I tried and I'm
going to show you like if I go here and
I delete this and I add like a new
between
and I try using something like minus 7D
which means the last seven days then I
just can't submit it like I don't get an
entry so this is something that we have
to do in code still until this gets
added
but it's not that hard so I added
between I say minus seven days but I can
also say minus one weak producing debt W
but we're going to use minus seven days
and today and that means that I want any
task that was between seven days ago and
now and if I click on that you'll see
this one happening but that's not a good
example because I just made one so let's
go to a specific date and let's go like
a week ago so the 21st
and I'm going to go here and I'm going
to make another to do I'm gonna go back
and you still don't see it showing up
now if I go back to this one to this
between and I said like hey let's turn
that one into minus two weeks
then you see the result happening so
with the between you can really figure
out where tasks are and of course this
also works in the plus so you can say
something like between today and plus
seven days if you have any tasks
scheduled for the future to see what's
adding your way
now let's dive in some of the really
neat features of logseek and that is
properties
I made these two entries here for play
games and I'm gonna give them a property
so I click on the to do I press shift
enter so I stay within the block and I'm
gonna say system
I'm going to say I'm going to play games
on the Xbox
and then once I've done that one I'm
gonna make a new one here as well also
going to shift enter and because system
is now known I can just do two columns
and then type system
and it will show you all the values it
knows in this case Xbox but I'm going to
add PlayStation
I might add switch as well but no need
so now I have these two tasks what can I
do with these properties that I just
added now let's go back to our live
query that's under here I'm going to
remove the between because I want the
things that are on this page and you can
like see the entries that are made here
and you also see the entries that are in
the journal and then I'm going to say
like hey I want only the tasks that have
the property system so I'm going to go
here
I'm going to say property
I'm going to type in system
and then I can also pick if I want to
have just the PlayStation ones or just
the Xbox Ones or just oh I'm gonna pick
all in this case
if you look at the query you see that
property system
and then I just get to Do's that are
marked system and now we get to like one
of the really cool features because I
can go up the top here and turn it into
a table
and then I not just have like an
overview of all these blocks but I also
have like a list of that property behind
it so in this case showing me on what
system and in what block and it's going
to get even more funky once we get into
page properties which I'll show right
after this you know this is on this page
you might not care about the page so you
can click on this one and say like nah
just
leave the page out of it and so you can
like update your list and you can also
sort
and as you just see also filters are
selling hey I just want the Xbox stuff
let's move remove this one go here to
property
say that I want some system and I just
want the Xbox lines and I'll just get
the Xbox so using properties really
makes it possible for you to slice and
dice all the blocks that you are making
and I'm going to give you like a quick
example of how I use that for pages
now that we had block properties let's
look at page properties and one of the
strongest ways for me to use page
properties is by using them inside my
journal because there's things that I
can track over time let me give you a
quick example here I need to keep track
of the hours that I work and it's not
that I have to keep track of like every
minute for that I would need a much more
fine-grained method or use it per block
but I need to keep track of like did I
work eight hours or six hours on a day
you know did I go home early for example
and the way I do that is I have a
template that I start every day and that
adds hours as a first block property so
let's say I worked eight hours today and
then I get this like in my journal on
the top it says like hours is eight now
I prep this so if I'll go back you see
that I got a couple of hours filled in
and then what I can do is I can click
and it already shows me this data
because I've already done this before
but if I go to that I get to the hours
page which is the page for the property
and I created a small query that
basically says nothing else except page
property hours so let's let's build this
from scratch I say query and I go page
property so you got property here but I
said like no I want Pages go pages I say
property again I say hours
foreign
select all and then what happens is I
get this list of all the dates in my
calendar and the hours worked created at
because it's a page so it knows when
it's created and when it's updated and I
also experiment a bit with mood as you
can see here then let's sort it at the
page level and that means that now I get
back and go like hey if I fill my
timesheet I can open this and I just see
like the hours that I filled in every
day and I can type it in to my
timesheets in like 10 seconds flat
because I got all the information that I
need over the last few days using page
properties is super useful not just in
things like the journal but also in
things like types so for example I make
lists for books so who's the author when
was it written what rating did I give it
I use it for projects is it still active
Who's involved what priority does it
have any type of thing that I want to
put on a page I can add these page
properties to and then use the simple
query Builder to filter for those
properties and get the results back in
the order that I need them this is a
really powerful function and I highly
recommend just playing around with it a
bit and figuring out what kind of
workflows you would like to use this for
remember if you're making a workflow
start with the end in mind so for
example this one was hey I have to fill
in this time sheet every week I need to
keep track of the hours every day now
before I dive into operators if you like
my content and want to help me out check
out my patreon link down below I'm not
sure yet what I'm going to do with it
but at least it will have early postings
of my videos while I can still do
something with the feedback that I get
answer questions from people and take
recommendations on videos or topics that
I should handle next
dive into operators and operators are
free shapes we have and or and not and
what they do is that they manipulate if
you want something yes or no in your
setup
and we've already seen so it
automatically happens if using the query
Builder if you start combining
properties that you want to see then and
will put those together and you will
only get results if all the things are
matched so and it's a to-do and it's at
work and it's a priority a those things
combined result into a thing then or is
just a tad different because that one
says like any of these things can match
and then we can start adding it already
now put a quick example up here and what
you can see is that I updated the list I
added a at work tag and I made this
small query so I said and so all the
things that are in here are and and then
the first element in that is an or and
what it does and let me see if I can
select just just this part
is it says or home or work and then a
task so that means that it has to be a
task and it has to have either home or
work or both both so you see the result
coming back which is basically the whole
list if I remove home somewhere let's
say then I change this one to phone then
that one gets removed because I didn't
say that I wanted to have a phone as
well so or is very nice if you're making
combined lists of different types you
want to put them together
and then finally we have not and not is
just the negation so if we're going back
to the example that I was just showing
where you see hey look I've got this one
and I'm saying like I would like to get
all the tasks in my system
so we're going cleaning this one up I
say just tasks
and I would say like but
I don't want to see any of the at home
stuff so I'm gonna go nut and then say
not at home
and then if I get a result I get a whole
bunch of tasks because it goes through
my whole system and gets all the tasks
that I have
with the exception of things like put
out the trash so let's make this a bit
simpler by saying by ant that we have
here and going like let me get me some
priority so priority and I just want to
get a
and then you get like a couple of things
but you'll see that none of these ones
are in there because none of these ones
are at home so if I take the call center
one here with phone and I would like add
priority a to it
this one would match because it's a
to-do it has a priority of a and it is
not at home and looking back at that
this gets updated and core contact is
there so the not parameter is mostly if
you want to remove something from the
list one of the ways that I use it very
often is I have a tag called an F which
I mean no filter and I add that if I
want to remove something from all my
filters so very often I have a not an F
at the end of my streak of queries and
that means that I can clean up long
lists that I have with elements that I
don't want to change so that they
automatically fall out of the filter but
I still don't want them in my end
results because I'm either done with
them or because they're just a thought
or comment that were added and they were
cluttering up my view
now simple crews are nice but they're
not perfect if I try messing around with
them very often things will break so if
I'm looking at this example where I said
like hey I made an oars like either or
home or phone and then I said like but
not like I tried to reverse that that
doesn't work I just get both of them
back so in most cases if it's not
working try to break it down into
smaller pieces I usually take a
processing order where I say like I have
and and then I have like all the lines
in there and I make multiple nuts or
ores in there if I have to build my
aquarium if you're going like three
layers deep then maybe it's better to
start diving into something like
Advanced queries try to limit it to
around two layers deep so just and and
then under and things like nut or or
but not what I'm doing here and and then
not and then or where you go like three
layers into the whole system okay so I'm
mostly focused on how to do it in text
and that is deliberate because while the
query Builder is nice it isn't perfect
and if it starts giving weird results
you'll have to dive in the code to fix
it so knowing how these elements fit
together really help you to either debug
or build a little bit more complex
queries without things breaking down
remember you're awesome keep it up and
see you in the next one
foreign
foreign
Browse More Related Video
Logseq Tutorial (2024) โ How to Use Logseq to Take Amazing Notes
SQL Basics for Beginners | Learn SQL | SQL Tutorial for Beginners | Edureka
*Secret* Google Search Course - Search Like a MASTER (Free)
MUST-KNOW Jira features for Scrum Masters
Navrae: Kriteria vir getalle
YouTube Automation with AI - 100% Free Course
5.0 / 5 (0 votes)