List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:November 1 2001 1:08am
Subject:Re: INSERT ... SELECT and VALUES? Is this possible?
View as plain text  
At 4:51 PM -0700 10/31/01, Nathan wrote:
>I have a table(2) with a different structure than the table(1) I'm 
>selecting from. I want to be able
>to grab some info from table1, put it in table2, along with some 
>variables from my php page. Is it
>possible to do like:
>INSERT INTO table2 VALUES 1,2,3 SELECT 4,5,6 FROM table1
>Or do I need to select into a temp table or my php form, get it all 
>in the right order, then insert
>it back into table2?
># Nathan

You can do it, but you don't use a VALUES clause.  Put all the values
in the SELECT statement.

For example, if you want set set columns a, b, c in table2 to
the contants 1, 2, and 3, and set the columns d, e, and f to
columns g, h, and i from table1, you'd do this:

INSERT INTO table2 (a, b, c, d, e, f) SELECT 1, 2, 3, g, h, i FROM table1
Auto_incrementIreneusz Piasecki31 Oct
  • Re: Auto_incrementPaul DuBois1 Nov
  • INSERT ... SELECT and VALUES? Is this possible?Nathan1 Nov
    • Re: INSERT ... SELECT and VALUES? Is this possible?Paul DuBois1 Nov
  • Re: Auto_incrementIreneusz Piasecki5 Nov
Re: Auto_incrementHeikki Tuuri5 Nov