SQL implementation code that inserts data from one table into another table

Source: Internet
Author: User

--The first of these cases

1 if the field of 2 tables is consistent and you want to insert all the data, you can use this method:

INSERT into target table SELECT * from source table;


2 "For example, to insert the articles table into the Newarticles table, it is:

INSERT into Newarticles SELECT * from articles;


3 If you want to import only the specified fields, you can use this method:

INSERT into Target table (field 1, Field 2, ...) SELECT Field 1, Field 2, ... From source table;

--Here's the second case

4 If you put one table's data in another table that does not exist:
SELECT * into target non-existent table from source table

5 If you want to import only the specified fields, you can use this method:

Select field 1, Field 2, ... into target non-existent table from source table

SQL implementation code that inserts data from one table into another table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.