SQL语句获取所有论坛和子论坛?

时间:2015-05-25 08:59:46

标签: php mysql sql

    | fid | fup | type  | name          |
 ---+-----+-----+--------+--------------+----------
    |  1  |  0  | group | category      |
    |  2  |  1  | forum  | forum_name    |
    |  3  |  1  | forum | forum_name2   |
    |  4  |  2  | sub   | subforum_name |
    |  5  |  2  | sub   | subform_name2 |
    |  6  |  0  | group | category2     |
    |  7  |  6  | forum  | forum_namex   |
    ........
 ---+-----+-----+--------+--------------+----------

有人能给我一个MySQL声明吗? 获得所有论坛和子论坛'当获得类别的fid时,附加到该组的fids。

1 个答案:

答案 0 :(得分:0)

尝试此查询。

SELECT f1.name as forums , f2.name as subforums FROM forum f 
LEFT JOIN forum f1 ON f.fid=f1.fup
LEFT JOIN forum f2 ON f1.fid=f2.fup
where f.fup=0 and f.fid=1