Adding an extra column value with INSERT … SELECT in MySQL

前端 未结 2 486
醉酒成梦
醉酒成梦 2020-12-05 15:53

I have two tables and my goal is to move specific data from the first table into the second table along with a reason for why that data was moved. For instance:



        
2条回答
  •  执笔经年
    2020-12-05 16:18

    Try this query:

    INSERT INTO bad_data_table VALUES (
    (SELECT * FROM raw_data_table WHERE id IS NULL LIMIT 1), "The ID is NULL");
    

    The subquery here needs to have 1 row!

提交回复
热议问题