JOIN with two queries in the same table

Asked

Viewed 1,462 times

0

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

It works that way

I have the PRODUCAO table and the BANCO table

In the production table, I take the ID of the bank in the tebela bank and returns me the name of the bank, however I have a second field called BANCO_SALDO

That takes the same BANK table the ID of the database and returns the name of the database.

How I can 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

1 answer

2


You can do a direct query with the database 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 too: http://sqlfiddle.com/#! 9/44f9b2/1

  • 1

    I get it, thank you !

Browser other questions tagged

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