MySql Update and Select in same query

In MySql, I try to do an UPDATE and a SELECT in the same query. I have try many examples from this site, but nothing work. (Variables, sub-query...)

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

SELECT status
FROM receipt
WHERE idreceipt = 220

Thank you

Upvotes: 1

Views: 642

Answers (1)

Simo Kivistö
Simo Kivistö

Reputation: 4453

If the above commands are fine for you as they are, just enter the semicolons at the end of the statements:

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

SELECT status
FROM receipt
WHERE idreceipt = 220;

Upvotes: 2

Related Questions