Consider this table:
Email | Message | Votes
------+---------+-------
Email1| Msg1 | 2
------+---------+-------
Email2| Msg2 | 1
------+---------+-------
Email3| Msg2 | 3
Now, I want to update the 3rd cell under Votes column using following query:
UPDATE tablename SET Votes=4 WHERE Message=Msg2
But the problem is that it will update the both cells under Votes, where Msg2 is present. But I want to update the cell where Email=Email3 and Message=Msg2.
Can it be done using UPDATE query?
Use multiple condtitions and join them with AND
:
UPDATE tablename
SET Votes = 4
WHERE Message = 'Msg2'
AND Email = 'Email3';
or using row-constructor:
UPDATE tablename
SET Votes = 4
WHERE (Message, Email) = ('Msg2','Email3');
EDIT:
I tried but it didn't work. It didn't update anything
So you have different data than you provided. Probably whitespaces. Try:
UPDATE tablename
SET Votes = 4
WHERE TRIM(Message) = 'Msg2'
AND TRIM(Email) = 'Email3';