I am five days into Laravel and after hours of watching Jeffrey Way I decided to delve into building an app to learn. I am migrating an old app across to L5 as a way to learn.
I just tried this syntax which worked without errors but returned an empty record, so incorrect output. The old SQL returns one record for the inputs below.
What is still different between the old SQL and the new L5 Query that the results are different? Thanks!
I am trying to replicate this SQL:
SELECT DISTINCT
TBA.*,
TBB.*,
MAX(TBA.mv_a_m_loss) as mv_a_m_loss
FROM TBA,
TBB,
TBC
WHERE TBB.id = 1
AND TBC.id = 1
AND TBB.conductor_temp = TBA.conductor_temp
AND TBB.conductor_size_mm_sq = TBA.conductor_size_mm_sq
AND TBA.mv_a_m_loss < 50
AND TBC.id = TBB.id
AND TBC.id = TBA.id
Here's my Laravel 5 Eloquent syntax:
$temp = DB::table('TBC')
->join('TBB', 'TBC.id', '=', 'TBB.id')
->join('TBA', 'TBC.id', '=', 'TBA.id')
->where('TBC.TBA_id', '=', 1)
->where('TBC.TBB_id', '=', 1)
->where('TBA.mv_a_m_loss', '<', 50)
->where('TBB.conductor_temp', '=', 'TBA.conductor_temp')
->where('TBB.conductor_size_mm_sq', '=', 'TBA.conductor_size_mm_sq')
->distinct()->get(['TBA.*', 'TBB.*', DB::raw('MAX(TBA.mv_a_m_loss) AS max_mv_a_m_loss')]);
dd($temp);
The result for the old SQL is a single record, the L5 result is a NULL record.