Mysql:从多级别类别获取文章?

时间:2013-10-11 10:40:11

标签: mysql recursive-query multi-level

假设我有一个像这样的article_category树:

GrandPa Cate
|______ Parent Cate 1 (article 1, article2)
|______ Parent Cate 2
|______|_____ Child Cate 1 (article 3, article 4)
|______|_____ Child Cate 2 (article 5)

表:

分类

id    | parent_id | title
----------------------------------------
1     | null      | GrandPa Cate
----------------------------------------
2     | 1         | Parent Cate 1
----------------------------------------
3     | 1         | Parent Cate 2
----------------------------------------
4     | 3         | Child Cate 1
----------------------------------------
5     | 3         | Child Cate 2
----------------------------------------

id    | cate_id   | title
----------------------------------------
1     | 2         | article 1
----------------------------------------
2     | 2         | article 2
----------------------------------------
3     | 4         | article 3
----------------------------------------
4     | 4         | article 4
----------------------------------------
5     | 5         | article 5
----------------------------------------

如何在选择Granpa Cate时获得所有5篇文章?

0 个答案:

没有答案