I have a SQL statement like that:
INSERT INTO TABLE_3(TABLE_1ID, TABLE_2ID)
SELECT ID FROM TABLE_1 WHERE NAME = '..',
SELECT ID FROM TABLE_2 WHERE NAME = '..';
But it doesn’t work. I just get an error
Statement … near “SELECT”: syntax error.
So how to do it correctly? There’s no example how to handle this with two selects from two different tables.
This would work:
INSERT INTO TABLE_1(NAME, AGE)
SELECT NAME, AGE FROM TABLE_2 WHERE ID = '..';
You need to join the 2 tables, since I don’t know your db structure, I am gonna assume that Name is the only common reference between the 2 tables, if that’s not the case, and you actually have something more solid (like an actual foreign key) then you should use that.
From your comment, it seems like there is no relation between TABLE_2 and TABLE_3, in which case, you can do this: