MySQL - Using If Then Else in MySQL UPDATE or SELECT Queries

前端 未结 3 1499
暖寄归人
暖寄归人 2020-12-13 06:03

How do I update a table and set different values upon the condition evaluating to True.

For instance :

UPDATE Table
SET A = \'1\' IF A > 0 AND A &         


        
3条回答
  •  粉色の甜心
    2020-12-13 06:36

    Here's a query to update a table based on a comparison of another table. If record is not found in tableB, it will update the "active" value to "n". If it's found, will set the value to NULL

    UPDATE tableA
    LEFT JOIN tableB ON tableA.id = tableB.id
    SET active = IF(tableB.id IS NULL, 'n', NULL)";
    

    Hope this helps someone else.

提交回复
热议问题