JOIN with two queries in the same table

0

I need two different results coming in the same table with JOIS

It works like this

I have the PRODUCAO table and the BANK table

In the production table, I get the bank ID in the bank bank and it returns the bank name, but I have a second field called BANCO_SALDO

It takes the same BANK table as the bank ID and returns the name of the bank.

How can I relate these two tables and show me the names in each field I need?

SELECT * FROM producao 
JOIN promotora ON id_promotora = promotora_produ
JOIN banco ON id_banco = banco_produ
JOIN B AS banco ON id_banco = banco_port_produ
    
asked by anonymous 18.12.2017 / 22:11

1 answer

1

You can make a query by doing it directly with the bank table. As in the example:

SELECT PROD.ID, B1.NOME, B2.NOME, PROD.VALOR
FROM PRODUCAO PROD
INNER JOIN BANCO B1 ON PROD.IDBANCOCONTA = B1.ID  
INNER JOIN BANCO B2 ON PROD.IDBANCOSALDO = B2.ID

I made an example running as well: link

    
19.12.2017 / 02:13