Created
June 21, 2016 10:56
-
-
Save PieterScheffers/189cad9510d304118c33135965e9cddb to your computer and use it in GitHub Desktop.
MySQL - Get id of updated rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql | |
# single row update | |
SET @update_id := 0; | |
UPDATE some_table SET column_name = 'value', id = (SELECT @update_id := id) | |
WHERE some_other_column = 'blah' LIMIT 1; | |
SELECT @update_id; | |
# Multiple rows updated | |
SET @uids := null; | |
UPDATE footable | |
SET foo = 'bar' | |
WHERE fooid > 5 | |
AND ( SELECT @uids := CONCAT_WS(',', fooid, @uids) ); | |
SELECT @uids; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use can set SELECT find_in_set(id,@uids := CONCAT_WS(',', id, @uids))