This is my table data. If cat_parent_id is 0 that means its a parent, for example People and Culture is a parent with cat_id = 1, Employee Benefits and Certification is the child of People and Culture. However, Employee Benefits and Certification has also have child. Employee Benefits cat_id = 6, so his child is SSS Loan Inquiry, while Certification has a cat_id = 10, Certificate of Employment and SSS Certificate Of Contributions will be his child.
Expected output:
Admin and Facilities
• Safety and Security Related Concerns
• CCTV Footage
Information Technology
• User Account
• Enable / Disable Access
People and Culture
• Certification
• Certificate of Employment
• SSS Certificate of Employment
• Employee Benefits Request
• SSS Loan Inquiry
I have something like this at the moment no luck.
SELECT category.cat_id AS catId, category.cat_parent_id AS catParentId,
subcategory.cat_id AS subcatId,subcategory.cat_parent_id AS subcatParentId,
category.cat_name,
CONCAT( IFNULL(subcategory.cat_parent_id, category.cat_parent_id),
category.cat_parent_id, category.cat_id, category.cat_name) AS sorter
FROM ticket_categories AS category
LEFT JOIN ticket_categories AS subcategory ON subcategory.cat_parent_id =
category.cat_id
GROUP BY category.cat_id
ORDER BY sorter
Main Goal is to sort the data alphabetically per parent (first priority), category (second priority), sub category (third priority). I'm playing with my alias sorter but I can't make it work.