Answer the question
In order to leave comments, you need to log in
How to assign the results of a SQL query to another column?
Good afternoon!
I have a test_field column and have a query that outputs the results as the
query itself:
SELECT my_table.id AS id, sum(child.qty) AS all_child_qty
FROM my_table
LEFT OUTER JOIN my_table as child
ON child.my_path LIKE (my_table.my_path || '%')
GROUP BY my_table.id
Answer the question
In order to leave comments, you need to log in
Rewrite to correlated query:
update my_table set all_child_qty = (select sum(child.qty) from my_table child where child.my_path LIKE (my_table.my_path || '%'));
UPDATE my_table
LEFT OUTER JOIN my_table as child
ON child.my_path LIKE (my_table.my_path || '%')
SET all_child_qty = sum(child.qty)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question