Can anyone teach me how can we use a query like this in Laravel 4.2
max(Created_dt) as MaxDate
t.Truck_Number = tm.Truck_Number AND
t.Created_dt = tm.MaxDate
this query is provided by someone else, can it be made better using laravel ?
Best How To :
If you have two tables...I have one solution for your question.. you dont need use joins for this. Table1 name 'truckgps' and table 2 name 'truckgpss' My Ans
$truckgps = DB::table('truckgps')->select('Truck_Number','Created','Latitude','Longitude','Speed','Heading ')->get();
foreach ($truckgps as $t)
$result = DB::table('truckgpss')->select('MAX(Created_dt) AS MaxDate ','Truck_Number')->where('MaxDate','=',$t->Created_dt )->where('Truck_Number','=',$t->Truck_Number)->groupBy('Truck_Number')
// if u need value convert array to string use another foreach loop here
foreach ($result as $value)
echo $value->Truck_Number; // now u can see the result truck no..
I think its help to u...Thank you ..