This may or may not be a simple question.
I have a query which selects all locations within a mile radius around a provided latitude and longitude. That part works perfectly, but I have additional information inside of another table that I would like to match to it. I've tried LEFT JOIN, but it's timing out.
SELECT *,
( 3959 * acos( cos( radians(40.7143528) ) * cos( radians( lat ) )
* cos( radians( lon ) - radians(-74.0059731) ) + sin( radians(40.7143528) )
* sin( radians( lat ) ) ) ) AS distance
FROM locations
LEFT JOIN informations ON
locations.name = informations.name
HAVING distance < 1
Here is what I would like this query to do:
- Provide all matching locations within a mile radius (works)
- Obtain the name of those stores (works)
- Match those names against the names of each store in the "informations" table
- Join all of the information in the matching rows together, where "locations.name" and "informations.name" match
The above query seems like it wants to work. I don't get any errors and it shows as valid in any MySQL formatter I use. However, I think I'm making an error somewhere which causes my tiny server to max processor usage.
To a more experienced set of eyes, would you see a reason why this would occur? Other than my server being near useless, of which I'm aware.