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 where student_id = 1, 200$)
If yes then and example will really help.
-Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try
INSERT...SELECTstatementif your column
IDisauto incremented, you don’t have to specify the1or else it will cause you an error.Another point is, if you only want to insert one column from the
student‘s table, you need yo specify the condition, so you will not get constraint error (assuming your column ID is the Primary Key)UPDATE 1
Seeing your comment, you have this query
you need to remove the
user_idcolumn above OR you need to add anIDin your select statement in order to match the number of columns.