Reputation: 41
i have this this biller table
|acq|iss|bnf|
=============
|2 |13 |553|
|9 |8 |553|
|14|22 |553|
and this bank table
|bank id| bank_name |
====================
|2 |bank bri |
|8 |bank mandiri|
|9 |bank bni |
|13 |bank permata|
|14 |bank bca |
|22 |bank cimb |
|553 |bank mayora |
how to produce this table with sql ?
|acq |iss |bnf |
=====================================
|bank bri |bank permata |bank mayora|
|bank bni |bank mandiri |bank mayora|
|bank bca |bank cimb |bank mayora|
Upvotes: 2
Views: 40
Reputation: 37473
You can try the below - you need to join with multiple instances of bank table
select b1.bank_name as acq, b2.bank_name as iss,b3.bank_name as bnf
from biller b inner join bank b1 on acq=b1.bank_id
inner join bank b2 on iss=b2.bank_id
inner join bank b3 on bnf=b3.bank_id
Upvotes: 1