0

Let's consider 2 tables with a "tree" table having id as primary key. And a "link" table having (src_id, dst_id) as primary key, and those foreign keys:

  • src_id (referencing the tree table)
  • dst_id (also referencing the tree table)

How can we select all the sources of the sources of the sources a particular tree (without going crazy)?

Edit:

SQL> DESC tree;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| id      | int(11)       | NO   | PRI |         |       |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

SQL> DESC link;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| src_id  | int(11)       | NO   | FK  |         |       |
| dst_id  | int(11)       | NO   | FK  |         |       |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
Zag zag..
  • 6,041
  • 6
  • 27
  • 36
  • 1
    possible duplicate of [How to do the Recursive SELECT query in Mysql?](http://stackoverflow.com/questions/16513418/how-to-do-the-recursive-select-query-in-mysql) – paul Feb 05 '15 at 16:54
  • [Rendering Trees with Closure Tables](http://karwin.blogspot.com/2010/03/rendering-trees-with-closure-tables.html) – Marcus Adams Feb 05 '15 at 17:23
  • Thanks for the links. Yes there's pretty much the same wanted-feature. However my question is specific because over 2 tables. – Zag zag.. Feb 06 '15 at 00:59

0 Answers0