John Bokma MexIT
freelance Perl programmer

Comments: ON DUPLICATE KEY with IF


Recently, for a project I am working on, I needed a conditional update of one column's value with the value of a different column part of the conditional. Luckily, this is possible and the syntax is what I expected it to be. In my specific case I wanted to keep track of the total times an object was updated, and the number of times it has been updated on the current list. Hence I needed two counters: one for the total number of updates, and one that's reset to 0 each time the list_id changes. Both columns where set default to zero. An outline of the SQL statement I use follows:

Read the rest of ON DUPLICATE KEY with IF.

Post a comment

Note that your comment doesn't show up immediately. I review each comment before I add it to this site.

Check the Follow this page option if you want to receive an email each time a comment is posted to this page, including yours. A link to turn this option off will be included with each email.

Internet adresses will be converted automatically. You can use the following notation to specify anchor text for a link: [url=]example text[/url].