I would like to insert data into table with one of the columns being populated by a select query. This is my SQL statement:
INSERT INTO books ( gid, type, membernumber, changedate, user)
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',
'mark'
);
What I want to achieve is for each insert, the membernumber will be taken from the mem table base on the JOIN it has with the group table.
When I execute this statement, I get the error:
More than one row returned by a subquery used as an expression
So for instance if the join will produce 20 rows then 20 records will be inserted with each member value replacing the membernumber in the insert for the 20 rows.
Update
I also have another query where two columns have to be replaced with SELECT-JOIN statements. @Tim has given me an example of one column. I want an example with two columns been filled with two SELECT-JOIN statements.