This is a follow up question to my previous question I would like to insert data into table with three of the columns being populated by a select-join queries. This is my sql statement::
INSERT INTO books ( gid, type, membernumber, changedate, order, user, task)
VALUES( '2b4493e8-cae8-4624-8177-fcc96553c5be',
2,
(SELECT member FROM mem m JOIN group g ON m.uid = g.sgroup),
TIMESTAMP '2017-01-03 00:00:00.000',
(SELECT order FROM orders o JOIN items i ON o.id = i.id),
'mark',
(SELECT task FROM tasks t JOIN lists l ON t.id = l.id),
);
What i want to achieve is for each insert, the membernumber, order and task will be taken from the mem, order and tasks tables base on the JOIN it has with their respective join tables.
member,ordersandtaskrelated? If you can build a single query that returns the desired rows from those tables, you can easily use that as the source of an insert statement (instead of thevaluesclause)