2 FK SELECT on the same table

0

Given this scenario:

Imagine a scenario in the field of oceanography, where table_A, in addition to the primary key, also needs to keep the direction of the wind (wind direction) and the direction of the wave (dir_condulation). Knowing that the table_ventos (id_vento, desc_vento) has all the possible directions, and both the fields dir_vento and dir_ondulacao are also winds, it would be possible that they stored the id_vento, in the future I will rescue the dsc_vento of the table wind from them, would be the fields dir_vento and dir_ondulacao foreign keys of the table_ventos.

How do I run select?

    
asked by anonymous 15.09.2016 / 12:07

1 answer

0

You should make two relationships with the same table, by naming them differently, like this:

SELECT A.Id, V.Dsc_Vento As Dir_Vento, O.Dsc_Vento As Dir_Ondulacao
  FROM tabela_A A
 INNER JOIN tabela_ventos V ON V.Id_Vento = A.Dir_Vento
 INNER JOIN tabela_ventos O ON O.Id_Vento = A.Dir_Ondulacao;

I hope I have been able to help.

    
15.09.2016 / 12:14