I need help with the following...
I've created a query that should join the records from another table based on a certain distance between two coordinates. I end up with a table that only has records with matching location names (like an inner join). I need every record in the table_customer_x and locationname should be a null if the distance between any location for that customer is > 250.
The query that I created:
SELECT t.customerid, t.geolatitude, t.geolongitude, tt.locationname
FROM `table_customer_x` t
LEFT JOIN `table_location` tt
on ST_DWITHIN(ST_GEOGPOINT(t.geoLatitude,t.geoLongitude), ST_GEOGPOINT(tt.latitude, tt.longitude), 250)
where tt.customer_id= 204
and t.timestamp > "2016-01-01"
and tt.latitude <= 90 and tt.latitude >= -90
table_customer_x looks like:
timestamp geoLatitude geoLongitude
2018-01-01 00:00:00 52.000 4.000
table_location looks like:
latitude longitude name customer_id
52.010 4.010 hospital x 204