user1005424
user1005424

Reputation: 67

MySQL - Update and Select in one query

I'm updating a table like so...

Update table Set count = count + 1 Where id = xx Limit 1

How to get the value of count without querying the table again? Can it be done in one query?

Thank you!

Upvotes: 2

Views: 599

Answers (1)

Johan
Johan

Reputation: 76567

No.

Update does not return a result set.
However you can get the count without having to query the table

UPDATE `table` SET count = @count:= count + 1 WHERE id = 'xx' LIMIT 1;

SELECT @count as LastUpdateCount;

Upvotes: 5

Related Questions