Help with construction of one update MySQL query
#4

I think that this should work if I understand the problem correctly:

Код:
UPDATE `acc_mobile_messages`
SET 
`archivedex` = (CASE `archived` WHEN 1 THEN %i ELSE `archivedex` END),
`archived` = (CASE `archived` WHEN 0 THEN %i ELSE `archived` END)
WHERE `databaseId` = %i;
We try to set `archivedex` first depending on the value of `archived` -- only if `archived` is 1 then it will update. Then we try to set `archived` to 1 if it is currently 0. If we tried to update `archived` first then it could get set to 1 and then subsequently the `archivedex` will get set too which is not what we want in your case (only one column is to be updated in the query).
Reply


Messages In This Thread
Help with construction of one update MySQL query - by Riwerry - 12.03.2018, 18:11
Re: Help with construction of one update MySQL query - by Maximun - 12.03.2018, 19:17
Re: Help with construction of one update MySQL query - by Riwerry - 12.03.2018, 22:22
Re: Help with construction of one update MySQL query - by mickmelon - 13.03.2018, 20:45

Forum Jump:


Users browsing this thread: 1 Guest(s)