how to combine multiple row in same table into 1 row with different column in sql join

Good day, (sorry for confusing title, its just hard to express 🙂 )

I have a transactions table with the following field:

Transactions TABLE
ID | amount | branch_id | supplier_id 
1  | 1,200  |    2      |  1

Subsidiary TABLE
ID  | Name      | Type
1   | supplier1 | 0
2   | branch_2  | 1

now I want to display this in my view with the id value properly so I joined the following table (im using laravel query builder)

$transactions = DB::table('transactions_table')
->leftJoin('subsidiary_table','transactions_table.supplier_id','=','subsidiary_table.id')
->get(array('transactions_table.id','subsidiary_table.name'));

Im 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..


Source: laravel

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.