I have this mysql query to do a search radius using Lat and Long as the center position:
$query = sprintf("SELECT Title, DateTime, ( 6371393 * acos( cos( radians('%s') ) * cos( radians( Lat ) ) * cos( radians( Lon ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( Lat ) ) ) ) AS distance FROM Locations HAVING distance < '%s' ORDER BY distance",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
I enter the Lat, Long, and radius in meters. Then the out put is title and datetime but I also need to get the user name from another table using the id.
The tables are:
Location
| Title | DateTime | UserID |
Users
| UserID | Username |
Is there anyway on how to use this query with Inner Join or Left Join? I’m also open to other ways on approaching this for best optimization.
You can use inner join: