I have below SQL statment
INSERT INTO my_counts (type,code,count) SELECT type,id ,1 from my_data WHERE user_id=10
ON DUPLICATE KEY UPDATE count = count + 1;
Here type,code is a composite primary key .
Could you please let me know how can I find out the number of records inserted and also the number of records updated separately ?
I know SELECT ROW_COUNT() gives the effected rows ( 2 for update and 1 for insert) .
But how to find out separately
1) the number of rows updated
2) the number of rows inserted
Thanks for your help
Regards
Kiran
I don’t know of a good way to get this from the diagnostics information.
In any case, supposing that you’ve controlled it so that only the rows just
INSERTed are in the table (or will only be queried), this can be simply retrieved after the fact:(please note that, as included in my SQLFiddle example, these numbers can actually be predicted from the base data).