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


*states within 500 mile radius of a zip code

*sql query used to find the states

Like with the 25 mile radius query, this query also works in MySQL 5.+, but not in 4.+. Again, I don't know why.

SELECT DISTINCT a.StateName, 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))))) < 500
     AND b.ZIPCode = '$zip'
     AND a.CityType = 'D';

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

SET SESSION SQL_BIG_SELECTS=1;