Update if the register exists otherwise insert. MYSQL -
let's suppose have following table in mysql db
table: debt
id | customer | amount --------------------- 1 | peter | $ 80 2 | john | $120 what want sum new amount of money pending 1 given customer. i've been doing far select check if customer exist in table. if update register sum of previous value plus new one. if register doesn't exist proceed insert.
as can see i'm using 2 operations, select , update, or select , and insert.
my question if there way 1 single operation
https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
set amount = amount + ?? in on duplicate update clause.
Comments
Post a Comment