Did some homework by myself, I find solution to the above problem by changing the code as below:
$query = new yii\db\Query(); $sql = $query ->select('a.vehicle_number, b.device_id, b.dated, b.speed, b.ignition, b.latitude, b.longitude') ->from('tk103_devices a, tk103_current_location b') ->where('a.device_id = b.device_id AND a.transporter_id='.$id) ->orderBy(['a.vehicle_number'=>SORT_ASC]) ->one(); $dataProvider = new ActiveDataProvider([ 'query'=>$sql ]); return array('count_flag'=>$countFlag, 'dataProvider'=>$dataProvider);
As per my scenario, I wanted to retrieve only first record. So, I used
one() instead of
Secondly, I was returning dataProvider as
$dataProvider->getModels(). I changed this to
$dataProvider only. Since "ActiveDataProvider does not take care at query limit." as per Fabrizio Caldarelli's answer below (or) above, it was returning all retrieved records.
Hope that helps someone having related issues.