is insert based on select on one of the column in MySQL possible?

后端 未结 3 1827
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 20:30

Is following insert based on select on one of the column possible in MySQL

INSERT INTO student_fees(id, name, fees) 
VALUES(1, SELECT name from students          


        
3条回答
  •  没有蜡笔的小新
    2021-01-17 21:16

    Just use the regular INSERT INTO ... SELECT syntax and select the other fields as constants as follows:

    INSERT INTO student_fees(id, name, fees) 
    SELECT 1, `name`, '200$' FROM students
    

提交回复
热议问题