I need to search and order by distance asc using two tables.
Explained:
Table 1: companies Id, CompanyName, address, location (point datatype)
Table 2 : branches Id, companyID, address, location (point datatype)
Table 1 is companies main data, main address, location and details etc, Table 2 is purely for a companies branches which also contains a locatiom point datatype.
I already have a query working with a haversine formula to query the nearest companies around a specific location (gotten through html5 location features). And it's working.
The problem is: it's only taking in account table 1 which has the main location. So, if the user is also near a branch of any other company, it won't be shown..
I need to make the query evaluate table 1 and table 2 locations and sort by distance taking in account both..
Is there a way this can be done ?