I could solve this on php side, but I would like to use only one query:
I have this rows that represents categories and there list order and subcategory pathway:
id order pathway 1 7 1 2 5 2 3 9 2/3 4 0 4 5 3 2/3/5
From that data I need to sort them primary by order number and then pathway to list subcategories inside there catetegory:
id order pathway 4 0 4 2 5 2 3 9 2/3 5 3 2/3/5 1 7 1
UPDATE: simple sort by order, pathway doesn't work in this case.
First row that need to be outputed is ID:4 because it has the lowest order number Then ID:2 because it has second lowest order number if we exclude ID:5 because it's inside categories 3 that is inside cat 2.
I also have column that represent category level (is it a main category or category inside some category and have deep) and column for category parent_id