So I have a table with 7 items. Lets call them: Car, Boat, House, Bike, Wheels, Sink, Bed. We can simply call the table Table
Each with the following assigned numbers:
(ID) (Item) (#) (parent_id)
1234 - Car - 1 - null
0000 - Boat - 2 - null
2222 - House - 4 - null
6545 - Bike - 5 - null
6547 - Wheels - 0 - 1234
4442 - Bed - 1 - 2222
1474 - Sink - 0 - 2222
Wheels is a child of car (or bike, doesnt matter) and sink & bed are children of House. The parent information is stored in the column called parent_id. It is null for everything that doesn't have a parent.
I need to use MySQL to sort this table via the assigned number order (called ordinal, the # in my tables here), however, retaining the parent-child order information. So the list should be sorted as follows:
(ID) (Item) (#) (parent_id)
1234 - Car - 1 - null
6547 - Wheels - 0 - 1234
0000 - Boat - 2 - null
2222 - House - 4 - null
1474 - Sink - 0 - 2222
4442 - Bed - 1 - 2222
6545 - Bike - 5 - null
How can I do this with mysql? We can assume all this information is on one table.