How to import data from one table to another table in sql

21,876

Solution 1

I think the code below will work for your case:

INSERT INTO table1 (column1,column2)
SELECT oldcolumn1, oldcolumn2
FROM table2 

Optionally you could add a where clause.

Solution 2

Use this code and check below links

The insert statement actually has a syntax for doing just that. It's a lot easier if you specify the column names rather than selecting "*" though:

INSERT INTO new_table (Foo, Bar, Fizz, Buzz)
SELECT Foo, Bar, Fizz, Buzz
FROM initial_table
-- optionally WHERE ...

The INSERT INTO ... SELECT FROM syntax is for when the table you're inserting into ("new_table" in my example above) already exists. As others have said, the SELECT ... INTO syntax is for when you want to create the new table as part of the command.

You didn't specify whether the new table needs to be created as part of the command, so INSERT INTO ... SELECT FROM should be fine if your destination table already exists.

OR Check this link

i hope this answer useful for you.

Share:
21,876
Sajith
Author by

Sajith

Self reminders I'm here to learn. Learning is an experience, everything else is just information. More to come.

Updated on July 09, 2022

Comments

  • Sajith
    Sajith almost 2 years

    I have two database there is two table both databse how to import data from database table to another database table in sql2008 standard edition. I have tried to export/import function but no luck . would you Please help me ?