I have following query:
$clinics = \DB::select('SELECT * FROM
(SELECT *,
(100 * acos(cos(radians(' . $lat . ')) * cos(radians(lat)) *
cos(radians(lng) - radians(' . $lng . ')) +
sin(radians(' . $lat . ')) * sin(radians(lat))))
AS distance
FROM clinics) AS distances
WHERE distance < 100
ORDER BY distance')
->join('countries', 'clinics.country_id', '=', 'countries.id');
When I run it I am getting following error:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function join() on array
Is it possible to perform JOIN with this query? I tried adding JOIN in the select query, but I am getting an error:
Column not found: 1054 Unknown column 'clinics.country_id' in 'on clause' (SQL: SELECT * FROM (SELECT *, (100 * acos(cos(radians(43.1557012)) * cos(radians(lat)) * cos(radians(lng) - radians(22.5856811)) + sin(radians(43.1557012)) * sin(radians(lat)))) AS distance FROM clinics) AS distances JOIN countries ON countries.id = clinics.country_id WHERE distance < 100 ORDER BY distance)
The query in question:
$clinics = \DB::select('SELECT * FROM
(SELECT *,
(100 * acos(cos(radians(' . $lat . ')) * cos(radians(lat)) *
cos(radians(lng) - radians(' . $lng . ')) +
sin(radians(' . $lat . ')) * sin(radians(lat))))
AS distance
FROM clinics) AS distances
JOIN countries ON countries.id = clinics.country_id
WHERE distance < 100
ORDER BY distance');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire