# Viewing all the notes (not a graph of them) linked to this note?

**URL:** https://org-roam.discourse.group/t/viewing-all-the-notes-not-a-graph-of-them-linked-to-this-note/126
**Category:** How To
**Created:** [May 14, 2020, 1:14pm UTC](https://org-roam.discourse.group/t/viewing-all-the-notes-not-a-graph-of-them-linked-to-this-note/126 "2020-05-14T13:14:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![titaniumbones](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/titaniumbones/32/105_2.png) [@titaniumbones](https://org-roam.discourse.group/u/titaniumbones)
#### Post date: [May 14, 2020, 1:14pm UTC](https://org-roam.discourse.group/t/viewing-all-the-notes-not-a-graph-of-them-linked-to-this-note/126/1 "2020-05-14T13:14:50Z")

</div>

Not sure if I understand this right, but is it possible to view the content of all the notes that are linked to a particular note, or some other `org-agenda` or `org-ql`-type operation which will construct a buffer containing some set of notes? So for instance, I would like to quickly share all the notes I took on all the references I entered yesterday, or all the references related to topic A. Is this something I can do in a straightforward way, or do I need to write code that will do that for me?

Thanks again!

---

<div class="post-metadata">

### Author: ![jethro](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@jethro](https://org-roam.discourse.group/u/jethro)
#### Post date: [May 14, 2020, 1:58pm UTC](https://org-roam.discourse.group/t/viewing-all-the-notes-not-a-graph-of-them-linked-to-this-note/126/2 "2020-05-14T13:58:51Z")

</div>

A bit of understanding of the SQL DB will get you pretty far here. Say your topic A is file “[topic.org](http://topic.org)”, then you can run a query as follows (copied from [How to create a link to a org-roam search?](https://org-roam.discourse.group/t/how-to-create-a-link-to-a-org-roam-search/85/2)):

```auto
(org-roam-db-query 
  [:select [from] :from links :where (= to $s1)] (expand-file-name org-roam-directory "topic.org"))

```

That would return you the list of files related to the topic, and you can also then programatically generate a new Org file using the `#+INCLUDE` syntax for Org to export all those notes.

---

<div class="post-metadata">

### Author: ![titaniumbones](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/titaniumbones/32/105_2.png) [@titaniumbones](https://org-roam.discourse.group/u/titaniumbones)
#### Post date: [May 14, 2020, 8:37pm UTC](https://org-roam.discourse.group/t/viewing-all-the-notes-not-a-graph-of-them-linked-to-this-note/126/3 "2020-05-14T20:37:47Z")

</div>

Ah, that is super helpful, thank you. Doubtless some munging will be required but should be straightforward even for me. Thank you!

---

<div class="post-metadata">

### Author: ![YvesK](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/yvesk/32/381_2.png) [@YvesK](https://org-roam.discourse.group/u/YvesK)
#### Post date: [September 23, 2020, 11:59pm UTC](https://org-roam.discourse.group/t/viewing-all-the-notes-not-a-graph-of-them-linked-to-this-note/126/4 "2020-09-23T23:59:08Z")

</div>

Looking for a way to include backlinks into an export to html I found this used in [jethrokuan/dots](https://github.com/jethrokuan/dots/blob/0064ea2aab667f115a14ce48292731db46302c53/.doom.d/config.el#L495) that way:

```auto
  (defun jethro/org-roam--backlinks-list (file)
    (when (org-roam--org-roam-file-p file)
      (mapcar #'car (org-roam-db-query [:select :distinct [from]
                                        :from links
                                        :where (= to $s1)
                                        :and from :not :like $s2] file "%private%"))))
  (defun jethro/org-export-preprocessor (_backend)
    (when-let ((links (jethro/org-roam--backlinks-list (buffer-file-name))))
      (insert "\n** Backlinks\n")
      (dolist (link links)
        (insert (format "- [[file:%s][%s]]\n"
                        (file-relative-name link org-roam-directory)
                        (org-roam--get-title-or-slug link))))))
  (add-hook 'org-export-before-processing-hook #'jethro/org-export-preprocessor))

```
