How to join the tables, to the end to get the "tree" of attachments?

I'm back with the question, write an api for mobile apps. The application of conventional, such as community vk.com. So, the user to the post can attach a photo (from 1 to 6 pieces). Accordingly, pictures are loaded to the time when post id is not yet known. Table structure:
attachments - id, path, publication_id (id of the record, at the time of creation is 0, updated after creating the post)

Table posts:
wall - id, message

If you run this query:
SELECT * FROM `wall` LEFT JOIN `attachments` ON `wall`.`id` = `attachments`.`publication_id` ORDER BY `wall`.`id` DESC


Then we get the following structure:

id | message | path | publication_id

4| message | null | null
3 | message | attachment | the record id
3| the message | attachment 3| the record id
2 | the message | attachment 2 | the record id
2 | the message | attachment 2 | the record id
1 | the message | attachment 1 | id of the record

Ie if attachments in one record two, the answer will contain two rows, how to tree

4| message | null | null
3 | the message | attachment 3
------------------- attachment 3

2 | the message | attachment 2
-------------------attachment 2

1 | the message | attachment 1 | id of the record
April 3rd 20 at 18:55
1 answer
April 3rd 20 at 18:57
You have probably Materialized Path. Go googled: Materialized Path in PostgreSQL
MYSQL - Elijah.Leuschke commented on April 3rd 20 at 19:00
@Elijah.Leuschke, and it doesn't matter. As an example I took off. Otherwise look for Materialized Path - Carson_Green commented on April 3rd 20 at 19:03

Find more questions by tags MySQL