Use SQL statements to combine two tables in a database into a single table

Source: Internet
Author: User

SELECT * into new table name from (SELECT * FROM T1 UNION ALL SELECT * from T2)

This statement can be implemented to append the merged data to a new table.

Do not merge duplicate data SELECT * FROM T1 UNION ALL SELECT * FROM T2

Merge duplicate Data SELECT * FROM T1 Union SELECT * FROM T2

Two tables, table 1 table 2

If you want to incorporate table 1 data into table 2, use the following statement

Insert INTO Table 2 (Field 1, Field 2) Select field 1, Field 2 from B1

Note that the field names must be written clearly, and the automatic numbering is not allowed to be written in, to merge the AutoNumber field must rewrite an algorithm one record to add in

1 INSERT INTO B1 select * from B2

2 Select * Into NewTable from (SELECT * FROM B1 UNION ALL SELECT * from B2)

Use SQL statements to combine two tables in a database into a single 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.