Reputation: 61
I'm trying to wrap my head around using an IF statement within an UPDATE query.
I've got this code:
UPDATE privatethreads SET to_read = CASE WHEN to_user = 1 THEN '1' ELSE to_read
Which will not execute. I'm not sure what i'm doing wrong as i've been looking at every other thread relevant to this and phpmyadmin only tells me I have an issue after the end of the statement.
Upvotes: 0
Views: 49
Reputation: 1731
I think, what you want can be achieved in a more easy way:
UPDATE privatethreads SET to_read ='1' WHERE to_user = 1;
Upvotes: 4
Reputation: 18600
Try to add END at the end of query
UPDATE privatethreads SET to_read = CASE WHEN to_user = 1 THEN '1' END
Upvotes: 2