INSERT with SELECT

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

    Yes, absolutely, but check your syntax.

    INSERT INTO courses (name, location, gid)
    SELECT name, location, 1
    FROM   courses
    WHERE  cid = 2
    

    You can put a constant of the same type as gid in its place, not just 1, of course. And, I just made up the cid value.

    0 讨论(0)
  • 2020-11-22 14:48

    Correct Syntax: select spelling was wrong

    INSERT INTO courses (name, location, gid)
    SELECT name, location, 'whatever you want' 
    FROM courses 
    WHERE cid = $ci 
    
    0 讨论(0)
提交回复
热议问题