Inserting from a SELECT but changing one column?

前端 未结 6 756
忘了有多久
忘了有多久 2021-02-05 02:35

Wondering if there is a way to insert a row into a table from another, with exception of one column?

This is of course easy with a limitied amount of columns, but gets k

6条回答
  •  伪装坚强ぢ
    2021-02-05 03:07

    You can use temporary tables

    Create Temporary table

    CREATE TEMPORARY TABLE temp_table AS (SELECT * FROM MyTable WHERE ...);
    

    Update column

    UPDATE temp_table SET column='Value' WHERE ...;
    

    Or drop a column

    ALTER TABLE temp_table DROP column_name;
    

    Insert to destination table

    INSERT INTO MyDestinationTable SELECT * FROM temp_table;
    

提交回复
热议问题