INSERT with SELECT

前端 未结 8 1497
灰色年华
灰色年华 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:26

    Yes, it is. You can write :

    INSERT INTO courses (name, location, gid) 
    SELECT name, location, 'whatever you want' 
    FROM courses 
    WHERE cid = $ci
    

    or you can get values from another join of the select ...

提交回复
热议问题