If I want to simultaneously find a primary key and use it as a foreign key on an insert statement, then I can use the below query (found it here at this question)
INSERT INTO test (id, value)
SELECT foobar.id, 20
FROM foobar WHERE name = 'joe';
But what if I want to insert more than one foreign key? How would the statement look?
INSERT INTO test (id1, id2, id3, value)
SELECT foobar1.id, foobar2.id, foobar3.id, 20
FROM foobar1 WHERE name = 'joe'
FROM foobar2 WHERE name = 'joe'
FROM foobar3 WHERE name = 'joe';
Thanks
Does this work?: