0

我正在尝试在一个表中创建一个包含类别和子类别的论坛,并且我想在一个查询中选择所有 cat 和 subcat 但不知何故该查询给了我这样的错误消息

Unknown column 'fcat.fcat_id' in 'on clause'

虽然我不知道出了什么问题。顺便说一下,这是查询:

SELECT fcat.id          fcat_id, 
       fcat.name        fcat_name, 
       fcat.description fcat_description, 
       fcat.order       fcat_order, 
       fcat.url         fcat_url, 
       fcat.visibility  fcat_visibility, 
       fcat.parent      fcat_parent, 
       fcat.created_at  fcat_createdat, 
       fcat.is_active   fcat_isactive, 
       fsub.id          fsub_id, 
       fsub.name        fsub_name, 
       fsub.description fsub_description, 
       fsub.order       fsub_order, 
       fsub.url         fsub_url, 
       fsub.visibility  fsub_visibility, 
       fsub.parent      fsub_parent, 
       fsub.created_at  fsub_createdat, 
       fsub.is_active   fsub_isactive 
FROM   forum_categories fcat 
       LEFT OUTER JOIN forum_categories fsub 
                    ON fcat.fcat_id = fsub.fsub_parent
ORDER  BY fcat.fcat_id; 

有了这个错误,我什至无法测试查询结果是否符合我的预期。请帮忙。(^__^')

PS:如果你能帮助我简化陈述,那将对我有很大帮助。提前致谢。:)

4

1 回答 1

1

代替

ON fcat.fcat_id = fsub.fsub_parent

ON fcat.id = fsub.fsub_parent

询问:

SELECT fcat.id          fcat_id, 
       ...
FROM   forum_categories fcat 
       LEFT OUTER JOIN forum_categories fsub 
                    ON fcat.id = fsub.fsub_parent
ORDER  BY fcat.id; 
于 2013-06-29T16:27:38.510 回答