Update a table with the value of the same row

Viewed 3840

I have a table like this

id     Name   Parent_id   Text
1        x      0         
2        y      1         
3        Z      1        
4        A      2         
5        B      0         

Now i'd like to populate the column with the text of the column name depending on parent_id. If parent_id is 0 text value will be the name of the same row instead id parent_id!=0 it must find the right name

this is the output I'd like to archieve

id     Name   Parent_id   Text
1        x      0         x
2        y      1         x
3        z      1         x
4        a      2         y
5        b      0         b

Could someone help me?

2 Answers
Related