Sql logic needed

Hello People I have two tables…

Users
- id (
- username

sample data (1:alex,2:rocky,3:kothi)



linked_table
- from_id
- to_id
sample data (1:2,1:3)

I want to fetch and display from_name and To_name from linked_table.i tried joining and selecting but it fetches only from_name

    $Get_Linked_name = DB::table('linked_table')
    ->join('users','linked_table.from_id','=','users.Id')
    ->where(array('linked_table.from_id'=>1))
    ->select()->get();

'linked_table.from_id'=>1 is linked to 2,3 now i want to fetch username of 2,3 i know it can be done using another empty array and foreach loop but is there any other better options?

updated: From_name and To_name are nothing but username of users table


Source: sql

Leave a Reply