* select from where To execute the source blocks load org-babel and hit "C-c C-C" with point inside the block. The following function implements a simple SELECT-FROM-WHERE clause for remote org-tables: #+srcname: my-select-from-where #+begin_src emacs-lisp :tangle no :results silent (require 'org-babel-ref) (defun my-select-from-where (select-column table-name where-column where-entry) "Get an entry of a remote table with #+TBLNAME: `table-name' using a simple where clause: SELECT select-column FROM table-name WHERE where-column = where-entry `select-column' and `where-column' are zero-based indices (first column has index 0). The test is done using `equal'. Example: For the following tabe ,#+TBLNAME: mytable | 0815 | foo | | 4711 | bar | the function call (my-select-from-where 1 \"mytable\" 0 4711) returns \"bar\"." (let ((table (org-babel-ref-resolve-reference table-name nil)) select-entry) (dolist (row table) (if (equal (nth where-column row) where-entry) (if (null select-entry) (setq select-entry (nth select-column row)) (error "where-entry is not unique")))) select-entry)) #+end_src This requires the column which is used for indexing to have unique entries. Let's take this table for testing: #+TBLNAME: mytable1 | 0815 | foo | | 4711 | bar | First select the second column of the row where the first column equals 0815, then select the first column of the row where the second column equals "foo": #+srcname: test-select #+begin_src emacs-lisp :tangle no (list (my-select-from-where 1 "mytable1" 0 0815) (my-select-from-where 0 "mytable1" 1 "foo")) #+end_src Unfortunately, a table name ("mytable1") is replaced by something obscure, when we use it in the #+TBLFM line. Also, the function my-select-from-where converts numeric table entries to a numeric type, in contrast to the referencing in the #+TBLFM line. These helper functions work around these problems: #+srcname: my-select-from-where-helpers #+begin_src emacs-lisp :tangle no :results silent (defun my-select-1-from-table-where-0= (where-entry) (my-select-from-where 1 "mytable1" 0 (if (numberp where-entry) where-entry (string-to-number where-entry)))) (defun my-select-0-from-table-where-1= (where-entry) (my-select-from-where 0 "mytable1" 1 where-entry)) #+end_src Testing the helpers: #+srcname: test-helpers #+begin_src emacs-lisp :tangle no (list (my-select-1-from-table-where-0= 4711) (my-select-0-from-table-where-1= "bar")) #+end_src Now we can reference remote table rows using a dynamic index (press "C-c C-c" in the #+TBLFM line): #+TBLNAME: mytable2 | 4711 | | | | 0815 | | | #+TBLFM: $2='(my-select-1-from-table-where-0= $1)::$3='(my-select-0-from-table-where-1= $2)