how to write sql join query in laravel 5.2
<p>To make the report i need to write a join query. I wrote the join query in sql now, i need to write the same query in laravel 5.2. 
My sql query is given below.</p>

<pre><code>SELECT a.accountID, a.deviceID, b.description, a.timestamp, a.latitude, a.longitude, a.speedKPH as speed, a.heading, a.altitude, a.address, a.distanceKM as distance, a.odometerKM as odometer, a.IbatVolts, a.EbatVolts, a.ITempr, a.fuelLevel, a.inputState, a.IgnRuntime, a.GPSFixType, a.GPSPDOP, a.AlertType, a.speedLimitKPH, a.isTollRoad
FROM eventdata as a, device as b 
WHERE a.deviceID = '$deviceID'
  AND a.accountID = '$accountID'
  AND a.timestamp &gt;= $dt1
  AND a.timestamp &lt;= $dt2
  AND a.deviceID=b.deviceID
ORDER BY timestamp DESC
</code></pre>

<p>and i tried to write it in laravel also. the query is given below</p>

<pre><code>DB::table('device as b')
   -&gt;join('eventdata as a', 'a.deviceID', '=', 'b.deviceID')
   -&gt;where('a.deviceID', '=', '$deviceID')
   -&gt;where('a.accountID', '=', '$accountID')
   -&gt;where('a.timestamp', '&gt;=', '$dt1')
   -&gt;where('a.timestamp', '&lt;=', '$dt2')
   -&gt;select('a.accountID', 'a.deviceID', 'b.description', 'a.timestamp',
            'a.latitude', 'a.longitude', 'a.speed', 'a.heading', 'a.altitude', 'a.address', 'a.distanceKM as distance', 'a.odometerKM as odometer', 'a.IbatVolts', 'a.EbatVolts', 'a.ITempr', 'a.fuelLevel', 'a.inputState', 'a.IgnRuntime', 'GPSFixType', 'a.GPSPDOP', 'a.AlterType', 'a.speedLimitKPH', 'a.isTollRoad')-&gt;get():
</code></pre>

<p>Is this right? Can anyone tell me and help me to write the correct query.</p>