Store Locator by Postal Code

Retail Chain: Postal Code # Locations Distance  

(+) Add a Store

SELECT DISTINCT s.store_id, s.chain_id, s.name, s.address, s.city, s.state, s.zip, s.country, st.state_name, (3959 * ACOS(SIN(39.71 / 57.3) * SIN(z.latitude / 57.3) + COS(39.71 / 57.3) * COS(z.latitude / 57.3) * COS((z.longitude - (111.83)) / 57.3))) AS distance FROM zip_codes z, store_locations s, states st, store_chains c WHERE s.chain_id = c.chain_id AND 1 AND s.state = st.state_id AND ( (3959 * ACOS(SIN(39.71 / 57.3) * SIN(z.latitude / 57.3) + COS(39.71 / 57.3) * COS(z.latitude / 57.3) * COS((z.longitude - (111.83)) / 57.3))) <= 40 OR (3959 * ACOS(SIN(39.71 / 57.3) * SIN(z.latitude / 57.3) + COS(39.71 / 57.3) * COS(z.latitude / 57.3) * COS((z.longitude - (111.83)) / 57.3))) is NULL) AND z.latitude IS NOT NULL AND z.longitude IS NOT NULL AND c.is_active = 1 AND s.is_active = 1 ORDER BY distance ASC, st.state_name, s.city ASC, s.name ASC LIMIT 20