Conditional in Mysql

Asked

Viewed 721 times

0

I would like to get a string obeying a condition in Mysql. For example I have a table with a column name descritor which is filled with PT or MT, would like to get the string Português for PT and Matemática for MT in a consultation.

Example:

If descriptor = PT then Português

If descriptor = MT then Matemática

  • it seems to me the case of having a table with the names of the disciplines

1 answer

1


You can use CASE WHEN for that reason:

SELECT *,
CASE descritor  
    WHEN 'PT' THEN 'Português' 
    WHEN 'MT' THEN 'Matemática'
END AS Disciplina
FROM Tabela
  • It worked perfectly, thank you Ricardo Punctual

Browser other questions tagged

You are not signed in. Login or sign up in order to post.