I have a table like this:
+-----+-------------------------------------+--------------------------+---------------+
| id | parent_id | comment_text | date_posted |
+-----+-------------------------------------+--------------------------+---------------+
| 1 | 0 | 1 | 2020-01-08 20:40:00 |
| 2 | 1 | 1.1 | 2020-01-08 20:41:00 |
| 3 | 0 | 2 | 2020-01-08 20:42:00 |
| 4 | 0 | 3 | 2020-01-08 20:43:00 |
| 5 | 3 | 2.1 | 2020-01-08 20:44:00 |
| 6 | 2 | 1.1.1 | 2020-01-08 20:45:00 |
| 7 | 1 | 1.2 | 2020-01-08 20:46:00 |
How do I get ordered comments like this? (ORDER BY date_posted DESC
in each comment level and using one MySQL query because I need paging them using limit and offset).
comment_text
3
2
2.1
1
1.2
1.1
1.1.1