使用MySQL进行递归查询

时间:2015-02-05 16:45:27

标签: mysql graph-databases recursive-query

让我们考虑使用"树"以id为主键的表。 一个"链接"具有(src_iddst_id)作为主键的表和那些外键:

  • src_id(引用tree表)
  • dst_id(也引用tree表)

我们如何选择特定树源的所有来源(不要疯狂)?

编辑:

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)

0 个答案:

没有答案