home | us zip code lookup | zip code distance calculator | cities within 25 mile radius of a zip code | states within 500 mile radius of a zip code | us area code lookup


*cites within 25 mile radius of a zip code

*sql query used to find the cities

This query works in MySQL 5.+, but not in 4.+. I don't know why.

SELECT DISTINCT a.CityName, a.StateAbbr
     FROM zip_codes a, zip_codes b
     WHERE (2 * 3956 * ASIN(
          (SQRT(POWER(SIN(((a.Latitude*0.017453 - b.Latitude*0.017453)) /2 ) , 2 ) +
          COS( b.Latitude*0.017453 ) *
          COS(a.Latitude*0.017453) *
          POWER(SIN(((abs(a.Longitude*0.017453) - abs(b.Longitude*0.017453)))/2),2))))) < 25
     AND b.ZIPCode = '$zip'
     AND a.CityType = 'D';

To make it work in 5.+, I have to preface it with the following query:

SET SESSION SQL_BIG_SELECTS=1;