I have database table with parent and child entries. Ex.
+---+-------+-------+---------+
|id |title |parent | added |
+---+-------+-------+---------+
|1 |title1 |0 |09:50 |
|2 |title2 |0 |09:55 |
|3 |title3 |0 |10:00 |
|4 |title4 |3 |10:05 |
|5 |title5 |1 |10:10 |
|6 |title6 |2 |10:15 |
+---+-------+-------+---------+
I need to select only parent = 0
but in the order of latest child entry added to the table.
SELECT * FROM table WHERE parent=0 ORDER BY added DESC
this only gives me following output
+---+-------+-------+---------+
|id |title |parent | added |
+---+-------+-------+---------+
|3 |title3 |0 |10:00 |
|2 |title2 |0 |09:55 |
|1 |title1 |0 |09:50 |
+---+-------+-------+---------+
But since id 4, 5, 6 added in related to parent order is 2, 1, 3 so my expectation is
+---+-------+-------+---------+
|id |title |parent | added |
+---+-------+-------+---------+
|2 |title2 |0 |09:55 |
|1 |title1 |0 |09:50 |
|3 |title3 |0 |10:00 |
+---+-------+-------+---------+
What is the best way of writing this script?
FYI. Sorry for my poor English. If anyone can write this better way you are welcome. Thanks