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 thetree
table)dst_id
(also referencing thetree
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)