MySQL Snippets: Update Statement

MySQL LogoThis post is part of the series on MySQL Snippets.

The following MySQL snippet shows an example UPDATE statement for MySQL; I’m posting this as I have trouble remembering that the order of the MySQL statement is different to that of Microsoft SQL Server; in MySQL the SET clause comes after the JOIN clause, whereas in Microsoft SQL Server, with which I am more experienced, the order is reversed.

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
UPDATE bct_custom_fieldnotes AS cfn INNER JOIN bct_custom_fields AS cf ON cf.TableName = cfn.TargetTableName SET cfn.TargetDBTableName = cf.DBTableName WHERE cf.TableName <> cfn.TargetTableName;

What should we write about next?

If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.

Your Name

Your Email

Suggested Topic

Suggestion Details

Leave a Reply

Your email address will not be published. Required fields are marked *