I have the following table:
id | fruit | parent |
----------------------------
id_1 | apple | |
id_2 | | id_3 |
id_3 | pineapple | |
id_4 | plum | id_5 |
id_5 | plum | |
Is it possible with a subquery/lateral join to get the following output:
id_1 apple
id_2 pineapple
id_4 plum
So if the fruit is null, get the parent's fruit. Tried to get this with subquery, collected the linked parents to get the fruit values from that but in that case those were in pair with their ids, not with the "kids" ids. So something like this:
id_1 apple
id_3 pineapple
id_4 plum