MySQL: return updated rows

You can't combine these queries directly. But you can write a stored procedure that executes both queries. example:

delimiter |
create procedure upd_select(IN group INT, IN time INT)
begin
    UPDATE table SET time = 0 WHERE group_id = @group and time > @time;
    SELECT * FROM table WHERE group_id = @group and time > @time;
end;
|
delimiter ;

Apparently mysql does have something that might be of use, especially if you are only updating one row.

This example is from: http://lists.mysql.com/mysql/219882

UPDATE mytable SET
mycolumn = @mycolumn := mycolumn + 1
WHERE mykey = 'dante';

SELECT @mycolumn;

I've never tried this though, but do let me know how you get on.


This is really late to the party, but I had this same problem, and the solution I found most helpful was the following:

SET @uids := null;
UPDATE footable
   SET foo = 'bar'
 WHERE fooid > 5
   AND ( SELECT @uids := CONCAT_WS(',', fooid, @uids) );
SELECT @uids;

from https://gist.github.com/PieterScheffers/189cad9510d304118c33135965e9cddb

Tags:

Mysql

Return