List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 20 1999 7:53pm
Subject:Re: [newbie] how to 'embed' SELECT into INSERT
View as plain text  
At 12:03 PM -0500 4/20/99, Davor Cengija wrote:
>       (newbie, 2 weeks with mysql, please forgive:-))
>       how can i do something like this:
>	("A", 1, (SELECT column FROM table2 WHERE something =
>       "something"));
>       yes, i know MySQL does not support embedded selections (yet)
>       and i'm probably asking for some function to do the job for
>       me.
>       maybe i first need to create some temp. table, INSERT INTO
>       temp_table SELECT column FROM table2 WHERE etc... and then put
>       those data into table1 like
>INSERT INTO table1(third_column) SELECT * FROM temp_table;
>       is there a better way?

Couldn't you just use INSERT INTO ... SELECT ... with your original

INSERT INTO table1 (col1, col2, col3)
SELECT "A", 1, column
FROM table2
WHERE etc.

It looks to me like you were close with your first idea, but didn't
have the syntax quite right.  See:

Paul DuBois, paul@stripped
Northern League Chronicles:
[newbie] how to 'embed' SELECT into INSERTDavor Cengija20 Apr
  • Re: [newbie] how to 'embed' SELECT into INSERTPaul DuBois20 Apr
    • Re: [newbie] how to 'embed' SELECT into INSERTDavor Cengija21 Apr