How to exchange a column id for the name in the same table in Mysql?

Asked

Viewed 113 times

0

I want to select and instead of receiving the top number I want his name which is nm_depto. How can I do this?

SELECT d.id_numero_depto, d.nm_depto, d.id_numero_depto_superior FROM tb_depto AS d;
  • You want to change the column name from "id_numero_depto_superior" to "nm_depto" on the return of your query?

  • Yes, the corresponding figure

  • You will need to make a relationship, which is the name of the table that will have the nm_depto information?

  • the table is the same for both.

  • Isac did not understand

1 answer

0

I got it, that was the code:

select d1.id_numero_depto, d1.nm_depto, d2.nm_depto from tb_depto d1, tb_depto d2 where d1.id_numero_depto_superior = d2.id_numero_depto and d1.id_numero_depto_superior is not null;    

Browser other questions tagged

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