Here's how this works. You do your regular insert and at the end add a ON DUPLICATE KEY:
INSERT INTO tbl_registryproducts(reguserid, skuid, qty)
VALUES(#session.reguserid#,#form.skuid#,#form.qty#)
ON DUPLICATE KEY UPDATE qty = qty + #form.qty#
VALUES(#session.reguserid#,#form.skuid#,#form.qty#)
ON DUPLICATE KEY UPDATE qty = qty + #form.qty#
That's it. One line and you're done. And yes, I know I should be using cfqueryparam, but that would make this example a lot longer and a lot less readable.
Cool! What about updating multiple columns from a single sub-select from another table?
ReplyDeleteNot sure what you mean.
ReplyDeleteINSERT INTO
SELECT
FROM
?