I have more than two tables, while fetching 2,00,000 records from database taking too much time what I am expecting, so I need to convert it to sub queries?
The following code:
->join('track_details','track_details.code','=',$esealTable.'.primary_id')
->join('track_history as th','th.track_id','=','track_details.track_id')
->join('locations as l','l.location_id','=','th.src_loc_id')
->join('products','products.product_id','=',$esealTable.'.pid')
->where(['level_id'=>0, 'products.product_type_id'=>8003])
->whereIn('l.location_type_id',[741,744])
->whereIn('th.transition_id',[537,569]);
->get(['primary_id as iot','products.material_code','th.sync_time as datetime'])
->take(200000);