segunda-feira, 7 de julho de 2014

Get the ID from an UPDATED row in MYSQL

Today I had to help a coleague that asked me how to retrieve the key of the row updated in MYSQL.

I've never done that in MYSQL before, so I had to google it, and ended up finding this in stackoverflow:

SET @update_id := 0; 

UPDATE some_table 
SET    row = 'value', 
       id = (SELECT @update_id := id) 
WHERE  some_other_row = 'blah' 
LIMIT 1; 

SELECT @update_id; 


Worked as expected with a few adjustments to our database structure. This is the link to the original post: http://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql

--
Check out my new book on MySQL 5.6 http://www.amazon.com/dp/B00KSMWLH0

Nenhum comentário:

Postar um comentário

Leave your comment here!