I am using MySQL 5.5.52. Abbreviations: Lat = Latitude, Long = Longitude, NE = North East, SW = South West.
I have two SQL tables:
First table contains "Areas". Each Area consists of ID, NE Lat, NE Long, SW Lat, SW Long.
Second table contains "Points". Each Point consists of ID, Lat, Long.
I need a SQL statement that given a list of Area IDs will return the Points in those Areas. A Point is defined being in an Area if its Lat-Long lies within the square where the top-right and bottom-left corners are defined by the Area's NE Lat-Long and SW Lat-Long.
Note: I could change the Areas to be defined as a single Lat-Long with a radius, where Points are found within the 'circles'. But ideally I don't want to do this unless there is a much more efficient SQL statement to solve this way.
WHERE (Points.Lat > Areas.SWLat AND Points.LAT < Areas.NWLat) AND (Points.Long > Areas.SWLong AND Points.Long < Areas.NWLong)? I think a good question is why they aren't stored as spatial data (or are they)? If you update the post to include your DML it will help a lot. - Jacob HBetweenis inclusive so it's <= and >=. As for Join ON vs WHERE, they are usually the same execution. - Jacob H