Subject: insert into table with nest query

From: e-letter <[email-masked]>
Date: Tue, 25 Apr 2023 16:43:39 +0100

Readers,

table1
column1,column2
value1,value2

table2
column2,column3
value2, value3

table3
column1,column2,column3
value1,value2,value3

When value3 is first entered into table2, what are the correct
commands for value2 (in table2) and value1 (in table1) to be selected
for insertion into table 3?

INSERT INTO table3 SELECT ... WHERE value3='...';

The conceptual difficulty is how to use nested query correctly, or is
there a better method? Thank you.

---

From: Laurenz Albe <[email-masked]>
Date: Thu, 27 Apr 2023 11:28:03 +0200

> there a better method? Thank you.

The question is a bit unclear, but perhaps you mean

INSERT INTO table3 (column1, column2, column3)
SELECT table1.column1,
       table1.column2,
       table2.column3
FROM table1
   JOIN table2 USING (column2)
WHERE table2.column3 = 'value3';

Yours,
Laurenz Albe