MySQL: return updated rows

I am trying to combine these two queries in twisted python:

SELECT * FROM table WHERE group_id = 1013 and time > 100;

and:

UPDATE table SET time = 0 WHERE group_id = 1013 and time > 100

into a single query. Is it possible to do so?

I tried putting the SELECT in a sub query, but I don't think the whole query returns me what I want.

Is there a way to do this? (even better, without a sub query) Or do I just have to stick with two queries?

Thank You,

Quan


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


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 ;