Question

How can I update 2 columns at a time?

I tried the following statement, which doesn't work:

UPDATE exercises
SET times_answered = times_answered + 1
AND av_answeringTime = av_answeringTime + ( (av_answeringTime / (times_answered) ) + ?) * (times_answered + 1)
WHERE name = ?
Was it helpful?

Solution

Use a comma instead of your "AND":

UPDATE exercises
SET times_answered = times_answered + 1,
    av_answeringTime = av_answeringTime + ( (av_answeringTime / (times_answered) ) + ?) * (times_answered + 1)
WHERE name = ?

OTHER TIPS

The SQL UPDATE syntax is:

UPDATE table SET
  column1 = value1,
  column2 = value2
WHERE condition

Instead of the AND you need a comma

Try something like this...

UPDATE exercises
SET times_answered = times_answered + 1,
av_answeringTime = av_answeringTime + ( (av_answeringTime / (times_answered) ) + ?) * (times_answered + 1)
WHERE name = ?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top