M
M
MaoCzedun2015-07-03 10:08:43
MySQL
MaoCzedun, 2015-07-03 10:08:43

How to fill in the field?

Such a task, there is a table of reviews. Reviews are built hierarchically, that is, a tree. The original template is `Adjacency list , now the task is to add `full_path` the full path from the root to the current branch , for `parent_id` = 0 it's easy . full_path = concat(0,'/',this.id) . I am doing now for those whose parent_id is not zero. The idea is to set the element's full_path to parent.full_path plus the element's id . But the muscle does not work, how to fix the request.

UPDATE  `barmen_comments` 
set full_path=CONCAT(0,'/',(SELECT barcom.`full_path` FROM `barmen_comments` as barcom WHERE   barcom.`comments_id` =  `barmen_comments`.`parent_id`)) 
WHERE `barmen_comments`.`parent_id` != 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaoCzedun, 2015-07-03
@MaoCzedun

UPDATE `barmen_comments` as b1 INNER JOIN `barmen_comments` as b2 ON b2.comments_id = b1.parent_id SET b1.full_path = CONCAT(b2.full_path,'/',b1.comments_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question