insert data from one table to another in mysql

后端 未结 10 523
深忆病人
深忆病人 2020-11-29 18:39

i want to read all data from one table and insert some data in to another table. my query is

  INSERT INTO mt_magazine_subscription ( 
      magazine_subscr         


        
相关标签:
10条回答
  • 2020-11-29 19:36
    INSERT INTO destination_table ( 
          Field_1, 
          Field_2, 
          Field_3) 
    SELECT Field_1, 
          Field_2, 
          Field_3 
          FROM source_table;
    

    BUT this is a BAD MYSQL

    Do this instead:

    1. drop the destination table: DROP DESTINATION_TABLE;
    2. CREATE TABLE DESTINATION_TABLE AS (SELECT * FROM SOURCE_TABLE);
    0 讨论(0)
  • 2020-11-29 19:38

    Actually the mysql query for copy data from one table to another is

    Insert into table2_name (column_names) select column_name from table1
    

    where, the values copied from table1 to table2

    0 讨论(0)
  • 2020-11-29 19:43
    INSERT INTO mt_magazine_subscription ( 
          magazine_subscription_id, 
          subscription_name, 
          magazine_id, 
          status ) 
    VALUES ( 
          (SELECT magazine_subscription_id, 
                  subscription_name, 
                  magazine_id,'1' as status
           FROM tbl_magazine_subscription 
           ORDER BY magazine_subscription_id ASC));
    
    0 讨论(0)
  • 2020-11-29 19:44

    If you want insert all data from one table to another table there is a very simply sql

    INSERT INTO destinationTable  (SELECT * FROM sourceDbName.SourceTableName);
    
    0 讨论(0)
提交回复
热议问题