Skip to content

Instantly share code, notes, and snippets.

@imliam
Created October 25, 2017 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imliam/a2c7fdf1d5a3ccded311dfce0277533e to your computer and use it in GitHub Desktop.
Save imliam/a2c7fdf1d5a3ccded311dfce0277533e to your computer and use it in GitHub Desktop.
Switch the values between two columns of the same row using a variable.
/*
|--------------------------------------------------------------------------
| Switch Column Values
|--------------------------------------------------------------------------
|
| Switch the values between two columns of the same row using a variable.
|
| Assigns a temporary variable "@tmp" to store "columnA", then replaces
| the columnA with columnB, then columnB with "@tmp".
|
*/
UPDATE user SET columnA=@tmp:=columnA, columnA=columnB, columnB=@tmp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment