public inbox for [email protected]  
help / color / mirror / Atom feed
insert into table with nest query
2+ messages / 2 participants
[nested] [flat]

* insert into table with nest query
@ 2023-04-25 15:43 e-letter <[email protected]>
  2023-04-27 09:28 ` Re: insert into table with nest query Laurenz Albe <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: e-letter @ 2023-04-25 15:43 UTC (permalink / raw)
  To: [email protected]

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.





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: insert into table with nest query
  2023-04-25 15:43 insert into table with nest query e-letter <[email protected]>
@ 2023-04-27 09:28 ` Laurenz Albe <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Laurenz Albe @ 2023-04-27 09:28 UTC (permalink / raw)
  To: e-letter <[email protected]>; [email protected]

On Tue, 2023-04-25 at 16:43 +0100, e-letter wrote:
> 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.

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






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-04-27 09:28 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-04-25 15:43 insert into table with nest query e-letter <[email protected]>
2023-04-27 09:28 ` Laurenz Albe <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox