Consider this statement:
INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE d=d+1;
I need the value of d.
Is it possible to obtain it without performing a further SELECT?
There is a unique index on a,b,c. Would this index be used for better performance? This table will have a large number of rows.
Assuming you will be running both queries using the same connection, You can use the
LAST_INSERT_ID(expr)function to set the current value ofd, and check the value ofLAST_INSERT_ID()together with theROW_COUNT()function to find out if the record was inserted or updated:You can also use session variables: