Saturday, March 4, 2017

GROUP concat with mysql join tables

I need to Join 3 tables for get data and im using SELECT GROUP CONCAT as well. I works fine when i joined 2 tables but when i trying to join three tables values gettings repeat. please advice .

below is my query

     $data = DB::table('festivals')
    ->join('namedesgs', 'festivals.id', '=', 'namedesgs.festival')
     ->join('vehicles', 'festivals.id', '=', 'vehicles.festival')
    ->select(DB::raw(" GROUP_CONCAT(vehicles.role SEPARATOR '\n') as role,GROUP_CONCAT(vehicles.size SEPARATOR '\n') as size,festivals.id,festivals.ref_no as ref_no, festivals.camping,festivals.tour_mgr_name,festivals.email,festivals.mobile,festivals.name_address, GROUP_CONCAT(namedesgs.name SEPARATOR '\n') as names,GROUP_CONCAT(namedesgs.designation SEPARATOR '\n') as designations"))
    ->groupBy('festivals.id')
    ->get();



via hansi silva

Advertisement