SQL switching values on a column

by stevenpcurtis   Last Updated June 13, 2019 03:06 AM

In interviews for software developer roles SQL questions can sometimes come up. There is a classic question around switching values in a column, typically swapping the gender of people in a table for example: enter image description here

the typical question asks you to do this in one statement (and the answer is here: Switching values in a column with one update statement)

However my question is NOT that.

My question is what is the naive approach, that is, how I can temporarily store the values. In fact I'd like to do this two ways: 1. In a temporary column (that does not persist after the statement) and 2. In a temporary variable.

Tags : mysql

Related Questions

Updated November 15, 2016 08:02 AM

Updated April 09, 2015 22:02 PM

Updated August 24, 2018 15:06 PM

Updated December 27, 2018 07:06 AM

Updated June 11, 2015 18:02 PM