this is my current query :
SELECT
id, name,
CASE
when geolocation='' then (select geolocation from location where id = q1.parent_id)
else geolocation end
FROM location q1;
this is an example of the table on which i make my query and the current result i get:
id | name | geolocation | parent_id
-- | ---- | ----------- | ---------
1 | aaaa | 0.0,0.0 |
2 | bbbb | 1.1,1.1 | 1
3 | cccc | | 1
4 | dddd | 2.2,2.2 |
5 | eeee | |
6 | ffff | | 3
id | name | geolocation
-- | ---- | -----------
1 | aaaa | 0.0,0.0
2 | bbbb | 1.1,1.1
3 | cccc | 0.0,0.0
4 | dddd | 2.2,2.2
5 | eeee |
6 | ffff |
this is not the result i want to get. what i would like is the request to be "recursive" so that the 6th location gets the geolocation of the "root parent" (in this case location aaaa). so my expected result is :
id | name | geolocation
-- | ---- | -----------
1 | aaaa | 0.0,0.0
2 | bbbb | 1.1,1.1
3 | cccc | 0.0,0.0
4 | dddd | 2.2,2.2
5 | eeee |
6 | ffff | 0.0,0.0
i tried to use the "cte method" but i can't get the result i want...
anyone has an idea?
best regards and have a great day
ps : careful, geolocation is a string