Get AI summaries of any video or article — Sign up free
Query syntax and logic: how to ask Roam questions with queries thumbnail

Query syntax and logic: how to ask Roam questions with queries

Robert Haisfield·
5 min read

Based on Robert Haisfield's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Use AND/OR/NOT to precisely control which blocks appear: AND requires all conditions, OR matches any, and NOT excludes.

Briefing

Roam queries turn a sprawling notes database into something you can interrogate: they let users ask for “everything I’ve written that matches these conditions,” then combine those conditions with AND/OR/NOT logic to surface exactly the right blocks. That matters because Roam’s value depends on being able to reuse past thinking—finding related insights, spotting connections, and pulling context into a “conversation” with one’s own database rather than manually hunting through pages.

At the core are three logical operators. AND requires all specified page conditions to be true for a block to appear in results (e.g., blocks mentioning both “page 1” and “page 2”). OR returns blocks that match any of the listed pages (e.g., “page 1” or “page 2”). NOT excludes blocks that match a given page condition. The real power comes from nesting these operators inside each other using parentheses-like grouping, so complex rules can be expressed precisely—similar to how math uses parentheses to control order of operations. With that structure, a query can demand multiple ideas at once while explicitly filtering out noise.

The transcript then walks through practical patterns. One common use is broad retrieval for preparation: if someone wants to prepare for a talk about “gamification,” they might query for any blocks related to “difficulty matching,” “failure states,” or “user goal.” Because those are treated with OR, the results pull together dispersed notes even if they were never written in one place.

Another pattern handles synonyms and aliases. “Perceptual control theory” and “PCT” are treated as equivalent labels, so a query can be placed on either page and still retrieve all relevant notes without forcing the user to remember which term they used when writing. The transcript also highlights a cleanliness tactic: excluding generic query pages (via NOT) so earlier query definitions don’t flood results.

A further refinement targets a specific author. To find only what Warren Mansell has written about perceptual control theory (or PCT), the query combines the OR group for the theory terms with an AND condition requiring Warren Mansell to be present. This yields a focused slice of the database rather than a broad thematic sweep.

Finally, the transcript shows how to connect two concepts by grouping their multiple aliases. For example, it groups “reward prediction error” with its alias “RPE” and connects it to “perceptual control theory” with “PCT,” also incorporating relevant author names like Wolfram Schultz and Warren Mansell. Using nested OR groups inside an AND structure, the query surfaces blocks where terms from both concept groups appear together—effectively mapping how two ideas relate across the database.

Overall, the takeaway is that once query logic becomes fluent, Roam’s chaos becomes navigable. Queries provide a reusable way to resurface notes based on meaning (tags/page names and aliases), not on where the notes were originally placed, enabling faster synthesis and stronger idea connections.

Cornell Notes

Roam queries let users ask their notes database questions using AND, OR, and NOT logic, then combine those operators with nested grouping to express complex retrieval rules. AND returns blocks containing all required page conditions; OR returns blocks matching any of several conditions; NOT excludes blocks matching a condition. Practical uses include pulling together dispersed notes for a topic (e.g., gamification concepts), handling synonyms/aliases (e.g., “perceptual control theory” and “PCT”), and filtering to a specific person (e.g., requiring Warren Mansell). Queries also support “concept pairing” by grouping aliases for two theories (e.g., perceptual control theory with reward prediction error) so results highlight where both ideas appear together.

How do AND, OR, and NOT change what Roam returns in a query?

AND means every listed condition must be present in a block for that block to show up (e.g., a block mentioning both “page 1” and “page 2”). OR means any one of the listed conditions is enough (e.g., “page 1” or “page 2”). NOT removes matches for a condition (e.g., “page 1 and page 2 and not page 3” returns blocks that include the first two ideas while excluding the third).

Why does nesting operators with parentheses-like grouping matter?

Grouping controls which conditions are evaluated together, similar to math order of operations. That lets a query require multiple constraints at once—such as combining an AND requirement with an embedded NOT—so the results reflect the intended logic rather than a flat list of terms.

What’s a good query pattern for preparing on a broad topic like gamification?

Use OR across the key sub-ideas so any relevant note surfaces even if it’s scattered. For example, a gamification query can include “difficulty matching,” “failure states,” and “user goal” as an OR set, pulling in blocks that mention any of those concepts.

How can queries handle synonyms so users don’t lose notes when they use different labels?

Treat aliases as equivalent inside the same query. For instance, include both “PCT” and “perceptual control theory” in an OR group so notes tagged with either term appear together. Then the same query can be placed on either page without forcing consistent tagging.

How can a query narrow results to a specific author’s writing?

Combine the concept conditions with an AND requirement for the person. In the transcript’s example, the query includes an OR group for “PCT”/“perceptual control theory” and also requires Warren Mansell to be present, so only Mansell-related blocks about that theory appear.

How do you query for relationships between two theories with multiple aliases?

Create two groups (Concept Group A and Concept Group B), each containing aliases and related author names, then require both groups to appear together. The transcript’s example pairs perceptual control theory (PCT) with reward prediction error (RPE), and includes Wolfram Schultz and Warren Mansell so the results highlight blocks where terms from both concept groups co-occur.

Review Questions

  1. When would you choose OR over AND in a Roam query, and what retrieval behavior would you expect?
  2. How would you structure a query to find notes about “perceptual control theory” written by Warren Mansell while excluding unrelated query pages?
  3. What’s the benefit of grouping aliases (like PCT and perceptual control theory) when trying to discover connections between two concepts?

Key Points

  1. 1

    Use AND/OR/NOT to precisely control which blocks appear: AND requires all conditions, OR matches any, and NOT excludes.

  2. 2

    Nested grouping (parentheses-like structure) lets complex logic behave predictably, like math order of operations.

  3. 3

    For topic prep, build OR sets of sub-ideas so scattered notes still surface together (e.g., gamification sub-concepts).

  4. 4

    Handle synonyms and aliases by placing equivalent terms in the same OR group so notes don’t “disappear” due to naming differences.

  5. 5

    Filter to a specific person by combining concept conditions with an AND requirement for that person’s name (e.g., Warren Mansell).

  6. 6

    To find relationships between two ideas, group aliases for each concept and require both groups to co-occur in the same block.

  7. 7

    Queries make note retrieval reusable and persistent, so writing can be scattered while still resurfacing when needed.

Highlights

Roam queries are built from AND, OR, and NOT, and nesting them enables logic as precise as math expressions.
Aliases like “PCT” and “perceptual control theory” can be treated as equivalent so retrieval works regardless of which label was used.
Requiring both a concept group and an author (e.g., Warren Mansell) produces a focused, high-signal slice of notes.
Concept-relationship queries can pair two theories by grouping their aliases (e.g., PCT with RPE) and surfacing blocks where both appear together.

Topics

Mentioned