2
I have the following doubt..
I have the example table - reply in the following format
*------------*--------------*
|resposta_id | INT |
|pergunta_id | INT |
|resposta | VARCHAR(45) |
*------------*--------------*
With the following records:
resposta_id pergunta_id resposta
1 1 ww
2 1 ww
3 2 xx
4 2 xx
5 3 xx
6 3 xx
7 3 xx
I’m looking to make a UPDATE to change the field of reply according to the value in the field question_id.
I tried so:
UPDATE sch_Pessoal.resposta
set resposta = CASE resposta
WHEN pergunta_id = 1 THEN 'aaa'
WHEN pergunta_id = 2 THEN 'bbb'
WHEN pergunta_id = 3 THEN 'ccc'
END
But the result is this;
resposta_id pergunta_id resposta
1 1 bbb
2 1 bbb
3 2 aaa
4 2 aaa
5 3 aaa
6 3 aaa
7 3 aaa
Someone can help?
SQL Fiddle of the structure:
Only one question. It wouldn’t be "WHEN answer_id" instead of "WHEN question_id"
– Fabricio
No Fabricio, in this case I wanted to modify the answer field, based on the field 'question_id' same
– Clayton Tosatti