Renaming values in mysql

Asked

Viewed 243 times

0

I have the following sql query:

   select nf,status from notas where status = 3

Instead of bringing the number 3 in the result of the sql query, I wanted to show another message: "completed".

how do I rename?

  • Need to make a Join with the status table to get the description.

1 answer

1


if you do not have the table with the description of the status, you can use the case when, otherwise, use the join with the other table:

select 
    nf,
    status, 
    (case when status = 3 then 'Concluido' else 'Em Aberto' end) as status_descricao
from notas 
where status = 3


select 
    n.nf,
    n.status, 
    ns.descricao
from notas n
inner join notas_status ns on ns.id = n.status
where status = 3

Browser other questions tagged

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