Lesson 1: What Are Logseq Queries and Why You Should Learn to Use Them

How valuable is a digital second brain when you can’t make it remember what you need?

After spending hours logging your thoughts and expanding your collection of notes, seeking through them probably gets difficult. The search bar you once loved now yields little useful. You like the ease of writing in Logseq, but finding back things gets increasingly frustrating.

Does this describe you? Then you’ve joined the right course!

Just like it requires skill to properly use search engines like Google and DuckDuckGo, it’s a skill to search your personal notes. By joining this course, you’re taking an important step to take ownership of your stored knowledge.

Maybe you’ve just heard of the term query, or maybe you’re a veteran programmer. Regardless of your current skill level, you will learn something in the coming two weeks.

Once you’ve gone through every lesson and challenge, you’ll know:

  • How computers (especially Logseq) seek through information
  • How to structure your notes to increase findability
  • How to use templates to guarantee a proper structure
  • How to use queries to gain insights from notes
  • How to use queries to power knowledge workflows

In the rest of this lesson, you’ll learn some basic definitions. This ensures we’re all on the same page and you start to see the possibilities of structuring and searching your notes.

Learn to converse with databases

Logseq is a database. While your notes may look like an outline within Logseq, or a collection of plain text files on your computer, under the hood Logseq is actually a database.

Logseq being a database means there’s a lot of data about data (metadata). Not only does Logseq keep track of the actual note text, but it also keeps track of what (grand)parents a block has, what links the block contains, and what other blocks link to it.

Understanding what data Logseq keeps about each block allows you to properly structure and navigate your notes. So even if you’re a total beginner and have only a few notes, having some basic knowledge about Logseq’s inner workings will pay off in the long term. But don’t you worry; you won’t have to become a programmer to become proficient with Logseq.

What are queries?

A query is just another way of saying “request for information.” Probably the most common type of query is the search terms you type into search engines like Google and DuckDuckGo.

Did you know that with search engines, you can search very precisely using keywords and filters?

A beginner search engine user may write a Google query like this:

highlights or notes from How to Take Smart Notes

An experienced Google user would likely write something like this:

highlights OR notes "How to Take Smart Notes"

Likewise, we can use keywords and filters in Logseq to request information from it. The way to write this request may be different in Logseq, but the question is exactly the same as the examples above:

{{query (and [[How to Take Smart Notes]] (or [[highlights]] [[notes]])) }}

The language you speak (well, write) to a computer to request information is called a query language. But, computers are dumb and can’t fill in the blanks. So when communicating with a collection of digital information, you have to be very specific about what information you want. That’s what you’ll learn in this course.

How can you harness the power of Logseq queries?

Tomorrow we’ll start simple by learning about Logseq’s basic data structure (its outline and links). In the days after, we’ll move on to how computers think using Boolean logic. Finally, we’ll get a clear picture of the grammar of Logseq queries.

Next week is all about applying what we learned to a series of build challenges. From Monday until Friday, you’ll get a daily challenge to build something useful with Logseq’s query language. We’ll provide you with a simple graph of example notes and help you write precise queries.

While you’ll receive the lessons in your mailbox, you don’t have to do them alone. There’s the #queries forum where over 150 fellow learners will be posting their experiments, asking questions, and providing help.

Let’s finish this first short lesson by reflecting on what you’ve learned.

Exercise

Answer the following questions in writing. Post your answers in this forum thread for today, and take some time to read the answers of others. Take note of who has similar learning goals like you, as this will come in handy next week.

  • What is a query?
  • What are query languages, and can you name examples of query languages?
  • What are some query languages you’ve worked with in the past?
  • Why do you want to learn how to write Logseq queries?

Next: Why you should link and indent your notes

After all this talk of databases and structure, you might wonder if you’ll ever be able to work with your mess of notes. So tomorrow we’ll start with the best practices for structuring our notes. Hint: it’s all about [[links]] and indentation (Logseq is an outlining tool after all!).

12 Likes
  • What is a query?

A query is a means of asking a computer to find specific information

  • What are query languages, and can you name examples of query languages?

A query language is a very specific way to talk to the computer in order to find the needed information

  • What are some query languages you’ve worked with in the past?

Other than search engines, I’ve had minimal experience with some databases.

  • Why do you want to learn how to write Logseq queries?

It’s important for me to learn to write effective queries so that I can get back the information when it’s needed. I know this is an overly broad response, but I’m still working out exactly what I need back out of my Logseq database as I’m retired and am trying to figure out the most effective way[s] of inputting information into Logseq for personal Bible Study, Recipe Collections, Bookmarks, and a Contact / Address Book.

Thank you again, @Ramses, for taking the time to organize these sprints and empowering us to not only be able to expand our vision as to just how powerful Logseq is, but for also equipping us to be able to effectively use it as well.

2 Likes

My Answers

  • What is a query?
    • A query is a question; it asks for data in the form of a filtered search; the question requires instructions as to the scope and focus of the information requested.
  • What are query languages, and can you name examples of query languages?
    • A query language is the set of rules that defines the syntax required to make a request that the database will understand.
  • What are some query languages you’ve worked with in the past?
    • I have worked with various search engines, SQL queries, and my spouse, who sometimes requires very specific questions in order to get the level of detail I need in an answer :face_with_spiral_eyes:
  • Why do you want to learn how to write Logseq queries?
    • I like to keep track of everything, and I am fascinated by the interconnectedness of almost everything. I often want to link disparate bits of information I didn’t know were related when I first collected them. Also, depending on the current context, the scope and focus of what I’m looking for may be very different, so I want to use a dynamic organizational method, rather than relying on a static, predetermined structure.
3 Likes

To answer:

What is a Query?

A query is a command that we used to retrieve information that we needed.

What are query languages, and can you name examples off query languages?

Query languages are structured language consists of vocabularies, syntax and semantics that used to retrieve language from a source, like database. SQL, NoSQL, Apache Cassandra Query Language

What are some query languages you’ve worked with in the past?

MySQL, MongoDB, and Cassandra Query Language

Why do you want to learn how to write Logseq Queries?

Since I am writing a thesis, which consists of arguments that extracted from various sources, I want to be able to easily recall and recover the information with the help of Logseq.

TBH I dont understand much about logseq, much because I still had folder-based file structured etched in my mind. Looking forward to learn together!

@LShark It sounds like you have experience with “complex queries”.

4 Likes
  • What is a query?
    a request for information, usually something you are trying to find specifically.
  • What are query languages, and can you name examples of query languages?
    different languages used to communicate with a computer, resources, or service.
  • What are some query languages you’ve worked with in the past?
    Kusto, PowerShell
  • Why do you want to learn how to write Logseq queries?
    Like everyone. I have a ton of notes, internal, external, work related, personal, family, random thoughts, things I want to capture, things I want to read later or correlate to existing data. I just want to be able to find the relative information when I need it.

:rofl: Yes I do!
But in all seriousness, I have found over the years that using search engines and queries in a technical aspect, has made me a better communicator with humans, and vice versa. We humans have a tendency to unconsciously assume that others - including computers - “know what I mean,” when, in fact, they probably don’t, unless we are very mindful about how we express ourselves.

2 Likes
  • Query
    • request for information
  • Query languages
    • in/formal specification for posing a Query
    • Examples
      • SQL
      • Multitudes of databases that roll their own
      • Web search engines
      • Microsoft Word “Find”
      • macOS Finder “Find”
  • I have worked with
    • all of the aforementioned examples and more in different apps
  • Why I want to learn Logseq queries
    • I have stored personal and work information on my computer for decades. I am constantly trying to find stored information, and constantly looking for better ways of managing that information so I can find it. I have yet to find a satisfactory solution.
    • At the moment, Logseq is the most promising solution I’ve yet seen, but one of the biggest issues for any method of storing and retrieving a huge number of disparate pieces of information is scalability.
    • Scalability comes in two forms:
      • Will the storage system support the volume of information that goes in?
        • Given the volume of data that modern databases can manage, I take as given that Logseq will be able to handle as much as I will be able throw at it.
      • Is there a satisfactory, easily understood, easily used query mechanism for finding what you’re looking for?
        • There is a sub-element to this: How easy is it to enter your information so that it can be successfully queried?
    • So, my bottom line is how easy will it be for me to manage all of my personal (no work, I’m retired) information, ranging from life notes, course notes, news references, software development projects, home and car maintenance records, receipts, and on and on.
      • Data entry and data query are key to this
2 Likes

What is a query?

It’s a request for information. Often it is a question asked in order to get information back from a database or a knowledge base.

What are query languages, and can you name examples of query languages?

It’s a formal way of asking a question to get information from a database or a knowledge base.

What are some query languages you’ve worked with in the past?

SQL, Enform (a report generation language from the 1980s that could be used on Tandem NonStop computers), queries for various search engines, and the search feature in Mozilla Thunderbird

Why do you want to learn how to write Logseq queries?

To get access in useful ways to notes that I have stored in LogSeq. To be able to extract information on certain topics in ways that will let me more quickly sift through it and then structure it into a more usable form, such as outlines to write from.

Q. What is a query?
A. command sentences using to request for extraction of information with purpose

Q. What are query languages, and can you name examples of query languages?
A. computer language which excute command for request imformation to DB. I don’t know if I can call it a “language”, but SQL.

Q. What are some query languages you’ve worked with in the past?
A. simple php for request data to MySQL

Q. Why do you want to learn how to write Logseq queries?
A. I would like to systematically retrieve data that I have written in logseq.

actually, I don’t know the data structure of logseq, so I’m perplexed how to write query.

for example, I don’t know the difference between the three types of search strings.

  1. “green” : enclosed in double quotation marks
  2. green : with #.
  3. [[green]] : enclosed in [[]].
    What is the difference when searching?

and another, about the date used in query, is the date of the journal or the page was created? Where can I find the timestamp of the block? Can we see the ID and properties of the block?

as such, there’s many things I want to know. I’m looking forward resolving these questions so that I could extract systematic data from my journal.

A query is a request for information from an information system.
A query language is a computer language for formulating queries.
I have worked primarily with SQL.
I want to be able to use queries to discover relationships in the data so that new ideas can emerge.

* What is a query?
  • A query helps me express my search terms in a way that the database is understanding.

    * What are query languages, and can you name examples of query languages?
    
  • Query languages, such as Datalog, are a unified set of commands that enable database-independent search.

    * What are some query languages you’ve worked with in the past?
    
  • I haven’t worked with any Query language before

    * Why do *__you__* want to learn how to write Logseq queries?
    
    • I want to apply Queries to the following:
      • Building a review system for my weekly Reviews
      • Something similar to the “on this day” feature in DayOne, which displays all entries from this day made in former years.
      • I would like to make goal planning possible in Logseq. As I am using Things for execution tasks, I want to use the task management system.
      • Finally, I want to build several small queries that I can insert via Keyboard shortcut (Keyboard Maestro) to aid me with little snippets of oversight, either in the right sidebar or as a removable object in current projects.

What is a query?

Suppose you need to find a particular piece of information from a complicated database with lots of data. A query is essentially a question you ask the database to try to narrow down or pinpoint that piece of information that you want.

What are query languages, and can you name examples of query languages?

A query language is any programming language that makes use of queries (asking questions about the database and returning the relevant pieces of information) to retrieve data from a database. Perhaps the most well-known is SQL where QL stands for ‘query language’.

What are some query languages you’ve worked with in the past?

A tiny bit of SQL, Google search if you count that, and you can use queries in data analytics programs such as R.

Why do you want to learn how to write Logseq queries?

I want to learn how I should structure my notes in an outliner so that they are easily searchable and I can later start incorporating more powerful tools. Ultimately, I want to create a tool that is useful both for writing down my thoughts in a diary-like fashion, and perhaps more importantly, that I can use in academia to help me to learn new concepts and improve my research.

2 Likes

Thanks a lot for organizing this learning sprint. I have started using Logseq a couple of months ago and I came to the point that I find it difficult to retrieve information in a fast and frictionless way.

  • What is a query?
    Query is a form of requesting information from a database.

  • What are query languages, and can you name examples of query languages?
    Query languages allow us to communicate our requests to our database in a very specific and precise way. Search engines typically use simple Boolean operations to enable filtering of the results so that they match more closely our request.

  • What are some query languages you’ve worked with in the past?
    My experience is limited to search engines.

  • Why do you want to learn how to write Logseq queries?
    After using Logseq for a few months, I came to a point where I find difficult to retrieve my data in a frictionless way. Despite having improved my productivity, I feel that I am not stuck and learning strategies on how to structure my database and retrieve information will take my productivity to another level. I find it amazing that Logseq provides such a powerful community and support to users in a way that everyone helps each other and share ideas in a very open way. Thanks a lot, @Ramses for guiding us through this important processes of structuring and retrieving data.

4 Likes
What is a query?

A description of a search to be performed for specific data.

What are query languages, and can you name examples of query languages?

Querly languages are the formal schemas (/ languages) for expressing queries. Which is a bit circular… so to expand, a formal language is one that can be parsed reliably by a computer to express a semantics intended by an author (and query is defined above).

What are some query languages you’ve worked with in the past?

SQL (esp. postgres-flavored), Mongo, GrahQL (maybe not really a QL), datalog

Why do you want to learn how to write Logseq queries?

See Working on a general approach to share a CV / Resume in Logseq. I’m generally interested in publishing subgraphs of my notes that include linear (journal) as well as aggregated (queried) information.

This lesson was extremely helpful! Absolutely cannot wait to learn more!

Thanks, @Ramses for providing this resource!

  • What is a query?
    A query is a request for information.

  • What are query languages, and can you name examples of query languages?
    A query language is a means of requesting information from a database. An example is SQL.

  • What are some query languages you’ve worked with in the past?
    I haven’t really worked with any query languages.

  • Why do you want to learn how to write Logseq queries?
    I use Logseq as a kind of technical users manual. I’m a consultant in Healthcare IT and I want to be able to reference past issues & their resolutions when I’m troubleshooting for a client. I’d like to use queries to become better at searching for and organizing information.

I was also inspired by @mat_rhein’s ideas:

Ditto to all of these! :grinning:

2 Likes
  • What is a query?
    • A structured statement intended to instruct a machine lookup
  • What are query languages, and can you name examples of query languages?
    • The particular structure a database expects. For example SQL.
  • What are some query languages you’ve worked with in the past?
    • SQL and MongoDB query language
  • Why do you want to learn how to write Logseq queries?
    • To facilitate workflows where I need to have a specific list of items on a page
  • What is a query?
    • A query is simply a search for some data by means of a filtered search. Keywords and operators enhance the scope and focus of the search, and serve as the filter’s “instructions”.
  • What are query languages, and can you name examples of query languages?
    • Query languages are a set of defined rules, or syntax, by which a user can input a query to retrieve the desired data. SQL, NoSQL, GraphQL are some popular services used to query databases. Workflows like Obsidian and Notion have their own query systems as well.
  • What are some query languages you’ve worked with in the past?
    • I’ve worked with SQL and GraphQL, as well as the searches in Notion, Obsidian, and some other services.
  • Why do you want to learn how to write Logseq queries?
    • I hope to actively curate my projects and data, as well as maintain control over my notes and data. With a well-polished system (even something simple as a #re-iterate tag), I can keep track of notes to be further developed for my study or application.
      I’m currently unfamiliar with the Logseq query syntax; this is an opportunity to see how the query works, as well as understand (and be aware of) all the properties the Logseq search uses, and thereby utilize them.
  • What is a query?
    • A query is a question with the expectation of getting an answer.
  • What are query languages, and can you name examples of query languages?
    • They are computer languages to make queries in a database or information system. I came across that definition from Wikipedia and couldn’t agree more with it
  • What are some query languages you’ve worked with in the past?
    • SQL
    • Datalog
  • Why do you want to learn how to write Logseq queries?
    • Because I want to better structure my notes in order to resurface the information when I need it. I dislike when I know I have saved a piece of knowledge but I am unable to find it again.
    • Because I want a better tool than the Logseq search bar and I am not efficient enough with advanced queries. I believe I may be underutilizing the simple queries
    • Because I love Logseq and the more I use it, the more amazing it becomes :slight_smile:
1 Like