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