Skip to main content

Quick tips: MySql Case

One project I worked on had a table with different spellings between English and French between an individual's title (masculine vs feminine in French). Since I did not want to spend too much time programming in the application itself, I came across the mysql "case" function during research.:

mySQL case is like a switch statement. Check out the official Manual Reference for a more through explanation.

Case When
    table1.Gender = 'Female'
Then
  table1.titlef
When
  table1.Gender = 'Male'
Then
  table1.titlem
End AS titlefr

Hope this helps someone else!