I’m trying to calculate all the correct answer a user gets and update it in the score table. But it gives me a fun little error.
UPDATE score
SET end_time = CURTIME(), final_score = COUNT(
SELECT *
FROM answered
WHERE (exam_id = 8 and student_login = 'user' and guessed = 1)
)
WHERE exam_id = 8 and student_login = 'user'
Error:
#1064 – You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘SELECT * FROM answered WHERE (exam_id = 8 and student_login =
‘user’ and gue’ at line 3
This should be simple enough right? Then what is up with this error? The select works on its own. and the update works without the final_score update.
Thanks for the help!
Should do it.
COUNT cannot (as far as I know) operate on sub queries.