我似乎无法弄清楚如何在这个 MySQL 选择中排序。我希望你能帮助我。
表格:
类别
catId, catParentId, catDisplay
1      0            1
2      0            1
3      0            1
4      1            1
5      1            1
类别翻译
transId, catId, catName, catDesc, langId
1        1      Title1   Desc1    1
2        2      Title2   Desc2    1
3        3      Title3   Desc3    1
4        4      Title4   Desc4    1
5        5      Title5   Desc5    1
语
langId, langName, langCode
1       Danish    da
2       English   en
我的查询:
SELECT `categories`.`catId`,
       `categories`.`catParentId`,
       `categories`.`catDisplay`,
       `categories_translation`.`catName`,
       `categories_translation`.`catDesc`,
       `language`.`langCode`
FROM   `categories`
INNER JOIN `categories_translation` ON `categories_translation`.`catId` = `categories`.`catId`
INNER JOIN `language` ON `language`.`langId` = `categories_translation`.`langId`
WHERE `language`.`langCode` = 'da'
现在,我得到了我想要的东西,但是有没有办法将子类别排序给他们的父母,所以结果如下所示:
期望的结果:
catId | catParentId | catDisplay | catName | catDesc | langCode
1       0             1            Title1    Desc1     da
4       1             1            Title4    Desc4     da
5       1             1            Title5    Desc5     da
2       0             1            Title2    Desc2     da
3       0             1            Title3    Desc3     da
我试过order by,但似乎可以得到我想要的结果。