Query syntax and logic: how to ask Roam questions with queries
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.
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?
Why does nesting operators with parentheses-like grouping matter?
What’s a good query pattern for preparing on a broad topic like gamification?
How can queries handle synonyms so users don’t lose notes when they use different labels?
How can a query narrow results to a specific author’s writing?
How do you query for relationships between two theories with multiple aliases?
Review Questions
- When would you choose OR over AND in a Roam query, and what retrieval behavior would you expect?
- How would you structure a query to find notes about “perceptual control theory” written by Warren Mansell while excluding unrelated query pages?
- What’s the benefit of grouping aliases (like PCT and perceptual control theory) when trying to discover connections between two concepts?
Key Points
- 1
Use AND/OR/NOT to precisely control which blocks appear: AND requires all conditions, OR matches any, and NOT excludes.
- 2
Nested grouping (parentheses-like structure) lets complex logic behave predictably, like math order of operations.
- 3
For topic prep, build OR sets of sub-ideas so scattered notes still surface together (e.g., gamification sub-concepts).
- 4
Handle synonyms and aliases by placing equivalent terms in the same OR group so notes don’t “disappear” due to naming differences.
- 5
Filter to a specific person by combining concept conditions with an AND requirement for that person’s name (e.g., Warren Mansell).
- 6
To find relationships between two ideas, group aliases for each concept and require both groups to co-occur in the same block.
- 7
Queries make note retrieval reusable and persistent, so writing can be scattered while still resurfacing when needed.