0

I am having 2 tables.

First table have values.

Second table do not have any values.

Most of the columns of both the tables are same.

I'm displaying 1st table values in frontend.

I want to insert that values which are displayed in frontend into the second table.

How can I do that?

Keren Caelen
  • 1,466
  • 3
  • 17
  • 38
user2514925
  • 931
  • 8
  • 33
  • 56
  • duplicate: http://stackoverflow.com/questions/74162/how-to-do-insert-into-a-table-records-extracted-from-another-table – whastupduck Jul 10 '13 at 10:01

3 Answers3

2

try this

INSERT INTO Table2(Name, ID) SELECT Name,ID FROM Table1 
Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68
0

Please search in stack.but u can use :

INSERT INTO Table2(LongIntColumn2, CurrencyColumn2)
SELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1;
Community
  • 1
  • 1
0

Basically there are two different ways to implement inserting data from one table to another table.

  • Method 1 : INSERT INTO SELECT You may use this method when table is already created in the database and you have to insert into this table from another table (from any database)

    Insert into table1 (column1, columnxyz) select column1, columnxyz from table2
    
  • Method 2: SELECT INTO This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table.

     Select Col1, Col2,Col100  INTO tableNew FROM alredyExisitingTable
    

Hope it will help

Rajeev Bera
  • 2,021
  • 1
  • 16
  • 30