dimanche 5 avril 2020

SQL if value in a row

I would like to update a row only if a condition on another row is met.

something like:

IF (SELECT `allow` FROM `accountlist` WHERE `id`='myid')<'1234' 
       THEN
           IF (UPDATE `accountlist` SET `upvotes`=`upvotes`+1 WHERE `user`='myuser')
               THEN (UPDATE `accountlist` SET `allow`='1234' WHERE `id`='myid');
           END IF;
       ELSE (/*return false*/);
END IF

in other words, if allow is lower than 1234 on myid, increment upvotes on another row and if you succeded set allow to 1234, otherwise return false or some error values.

Is it possible to run multiple queries when a condition is met?

Aucun commentaire:

Enregistrer un commentaire