Is there a way to insert two or more columns in a table from a SELECT statement?
E.g. If i do two insert:
INSERT INTO temp_table(dist0)
SELECT min(term1)
FROM graph_path
WHERE distance = 0
GROUP BY term2_id
ORDER BY term2_id;
AND
INSERT INTO temp_table(dist1)
SELECT min(term1)
FROM graph_path
WHERE distance = 1
GROUP BY term2_id
ORDER BY term2_id;
The result is:
dist0 dist1
1
2
3
4
5
6
How can i get a result like this? :
dist0 dist1
1 4
2 5
3 6
Postgresql version 9.5
AS ASKED: E.g. with term2_id
select term2_id, min(term1_id)
from graph_path
where distance = 1
group by term2_id
order by term2_id;
RESULT:
term2_id min
2 1507
3 107
5 1
term2_id
in the select lists.