I have a situation in my current website which is basically a complicated Questioner having around 400 questions.
I have three table .
1.Questions.
ID , QID, Question_Text,Event_name
2.Users
ID , Name ,Event_name
3.Answers
ID, User_ID ,Question_ID , Answer_text
So now each user will have an unique answers for each questions in Answers table.
My problems starts here. I updated new Questions in the Question table so The old users do not have answer in the answer table for the new question and hence my syatem is throwing error .
So I have to insert empty row into answers table for those users and those questions which do not exist in the answers table according to the Event .
Please help me write this query
My Attempt which failed
SELECT `user_id` FROM `answers` inner join users on answers.user_id=users.id inner join questions on questions.id=answers.question_id
Thanks
It would be drastic effect, if you have 10000 users and for each question 10000 records would be inserted. And with the time users would be increase.
If you can change schema then it could be an alternative way. for example- your Answer table look like- Answer(ID, User_ID as STRING, Question_ID),
Answer_text(Answer_id, User_id, Answer_text). In Answer table user_id column is string type column which have comma separated string of user_id (logically represent as foreign key by not actually). And in Answer_text table the user_id column is foreign key of Users table. When you get the record you can break the string by comma and get each user_id in array form.
Now when you add a question then by default all users id are concated in string form and inserted. Only 1 record is inserted. and when any user answer, you can insert into Answer_text table.