I can't seem to figure out how to order by in this MySQL select. I hope you can help me out.
Tabels:
categories
catId, catParentId, catDisplay
1 0 1
2 0 1
3 0 1
4 1 1
5 1 1
categories_translation
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
language
langId, langName, langCode
1 Danish da
2 English en
My query:
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'
Now, I get returned what I want, but is there a way to order the child categories to their parents, so the result looks like this:
Desired result:
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
I've tried order by, but can seem to get the results like I want.