How does mysql merge two data tables with the same structure?

Source: Internet
Author: User
At present, I have two data tables with the same structure. now I want to merge the two tables into one table, but I don't seem to find the option of merging in phpmyadmin, some merged SQL statements are also searched on the Internet, but an error is reported after execution. I don't know why. Is there any other way... at present, I have two data tables with the same structure. now I want to merge the two tables into one table, but I don't seem to find the option of merging in phpmyadmin, some merged SQL statements are also searched on the Internet, but an error is still reported after execution. I don't know why, but is there any other way to achieve this?

INSERT INTO order_zong (Ptname, Name, Mobile, orderdate, orderprice, ordertime) VALUES ( SELECT Ptname, Name, Mobile, orderdate, orderprice, ordertime from hnb);

The above code reports 12 errors, and the possible methods are not the same. please give me a simple method.

Reply content:

At present, I have two data tables with the same structure. now I want to merge the two tables into one table, but I don't seem to find the option of merging in phpmyadmin, some merged SQL statements are also searched on the Internet, but an error is still reported after execution. I don't know why, but is there any other way to achieve this?

INSERT INTO order_zong (Ptname, Name, Mobile, orderdate, orderprice, ordertime) VALUES ( SELECT Ptname, Name, Mobile, orderdate, orderprice, ordertime from hnb);

The above code reports 12 errors, and the possible methods are not the same. please give me a simple method.

If the data structure is the same, you can:

INSERT INTO `your_table_name`SELECT *FROM `destination_table_name`;

Insert into c SELECTFROM a UNION SELECTFROM B

Export the SQL statement and import it.

Insert into Table2(field1,field2,...) select value1,value2,... from Table1

INSERT IGNORE INTO order_zong (Ptname, Name, Mobile, orderdate, orderprice, ordertime)        SELECT Ptname, Name, Mobile, orderdate, orderprice, ordertime from hnb;

If the table is inserted again, insert into directly selects the table instead of values.
Note: You may report an error because the primary key is repeated during insertion.

Can I post the error? Will some fields define unique. An error occurred while importing the uniqueness conflict.

Or create a new table to merge.
Use union if deduplication is required
create table new_table SELECT Ptname, Name, Mobile, orderdate, orderprice, ordertime from order_zong union all SELECT Ptname, Name, Mobile, orderdate, orderprice, ordertime from hnb

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.