Reputation: 133
I have created a filter where users can find locations within a selected number of miles of a specific point,
My code is the following, I keep getting SQL syntax error near the "left join"
Not sure what the error is, if anyone could help that would be ace, or just point me in the right direction!
SELECT b.*, host,
(6371 *
acos(
cos( radians( '51.514294' ) ) *
cos( radians( `latitude` ) ) *
cos(
radians( `longitude` ) - radians( '-0.042857' )
) +
sin(radians('51.514294')) *
sin(radians(`latitude`))
)
) `distance`
FROM brunches b HAVING
`distance` < $range
LEFT JOIN hosts ON hosts.id = b.hostid
Upvotes: 0
Views: 22
Reputation: 133370
You have an having clause in wrong place (the having clause must not placed between from and join)
SELECT b.*, host,
(6371 *
acos(
cos( radians( '51.514294' ) ) *
cos( radians( `latitude` ) ) *
cos(
radians( `longitude` ) - radians( '-0.042857' )
) +
sin(radians('51.514294')) *
sin(radians(`latitude`))
)
) `distance`
FROM brunches b
LEFT JOIN hosts ON hosts.id = b.hostid
HAVING `distance` < $range
Upvotes: 1