Batch import data from one table into another table in MySQL (different cases)

Source: Internet
Author: User
Tags one table

In MySQL, bulk importing data from one table to another in the case of web development or application development, we often encounter situations where it is necessary to bulk import data from a MySQL table into another table, and sometimes even to specify an import field. This article will take the MySQL database as an example, how to import all the data of a table or the data of a specified field into the target table through the SQL command line. Category one, if the fields of the two tables (export table and target table) are consistent, and you want to insert all the data, you can use this method: (This method is only suitable for exporting two tables in the same database) insert INTO target table SELECT * from source table; For example, to articles Table is inserted into the Newarticles table, you can do this by using the following SQL statement: INSERT INTO Newarticles SELECT * from articles, category two, if you only want to import the specified fields, you can use this method: INSERT INTO Mesh Standard table (field 1, Field 2, ...) SELECT Field 1, Field 2, ... From source table; Note that the fields of both tables must be the same (field type), or a data conversion error will occur. Category three in addition to importing the specified fields, you also want to import some variables, invariants: For example: Content copy migration, the designated column table Caterel under a column copy to the B column one copy INSERT into Caterel (caterel field) Select b column field, fixed value (b column ID), now () from Caterel where column id=a column ID

Batch import data from one table into another table in MySQL (different cases)

Related Article

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.