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;

MySQL Snippets: Series Index

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

Like the other …Snippets series, this one may not get many posts as I’ll be using it to record things I need to remember. In thie series, I’ll be posting MySQL snippets; usually ones which highlight a difference between the MySQL and Microsoft SQL query syntax.

MySQL Snippets
Update Statement