I have a transactions table with the following field:
Transactions
ID | amount | branch_id | supplier_id
1 | 1,200 | 2 | 1
Subsidiary
ID | Name | Type
1 | supplier1 | 0
2 | branch_2 | 1
I want to display this in my view with the id value properly so I joined the following table (I'm using laravel query builder)
$transactions = DB::table('transactions_table')
->leftJoin('subsidiary_table','transactions_table.supplier_id','=','subsidiary_table.id')
->get(array('transactions_table.id',
'transactions_table.amount',
'subsidiary_table.name as branch',
'subsidiary_table.name as supplier'));
I'm confused on how can I get it to display like:
Display View
ID | Ammount | Supplier | Branch
1 | 1,200 | Supplier1 | branch_2
Thanks for clarifying..
Best Answer
I don't know if you want to put it in laravel, but, here's the query:
Try it.
PD: You can change the
JOIN
syntax forLEFT JOIN
if you want to return thet.ID = 1
record fromTransactions
even if one column don't match inSubsidiary's JOINs
.