INSERT with SELECT

前端 未结 8 1493
灰色年华
灰色年华 2020-11-22 13:49

I have a query that inserts using a select:

INSERT INTO courses (name, location, gid) 
            SELECT name, location, gid 
              FROM courses 
           


        
8条回答
  •  [愿得一人]
    2020-11-22 14:35

    We all know this works.

    INSERT INTO `TableName`(`col-1`,`col-2`)
    SELECT  `col-1`,`col-2` 
    

    ===========================
    Below method can be used in case of multiple "select" statements. Just for information.

    INSERT INTO `TableName`(`col-1`,`col-2`)
     select 1,2  union all
     select 1,2   union all
     select 1,2 ;
    

提交回复
热议问题