Monday, July 21, 2008

Mysql on update key

This is something cool that I found out today:

INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);

I've known about the on duplicate key but I would typically have to specify the values again. Here you can say values() and it will return what would have been inserted.

Very useful!

No comments: