MySql 在同一查询中更新和 Select

MySql Update and Select in same query

在 MySql 中,我尝试在同一查询中执行更新和 SELECT。 我已经尝试了该站点的许多示例,但没有任何效果。 (变量、子查询...)

UPDATE receipt
SET status = IF(status=1, 0, 1)
WHERE idreceipt = 220

SELECT status
FROM receipt
WHERE idreceipt = 220

谢谢

如果上述命令对您来说没问题,只需在语句末尾输入分号即可:

UPDATE receipt
SET status = IF(status=1, 0, 1)
WHERE idreceipt = 220;

SELECT status
FROM receipt
WHERE idreceipt = 220;