I am trying to write a query to insert values in table2 with reference to table1 using a foreign key.table2 columns are (quesid(primary key/auto-increment), ques,ques_desc). There is another table table1 its primary key is foreign key which is also AUTO INCREMENT. So using that i was trying to insert values. I have written below query:
insert into users_ques values("What is JAVA","Please SHare the details") from users WHERE quesid = 1;
mysql is giving me error at WHERE (where is not valid at this position). please help me so that i can sucessfully write this query.
Advertisement
Answer
The correct way to use select
for insert
insert into users_ques (column1,column2) select column1,column2 from users where quesid = 1;