Wir verwenden Cookies, um den bestmöglichen Service zu bieten. Wenn Sie unsere Seite nutzen, akzeptieren Sie den Einsatz von Cookies entsprechend unserer Datenschutzerklärung.

MySQL ZIP Code query without Google Maps

vom 08.05.2015

If you want to get ZIP codes which are located near to a given ZIP Code, the default way is to get altitude and longitude from Google Maps or any other GEO service and make your query.

The results will of course not be as good as with a GEO service, but in some cases this will be enough:

For example you want to get all entries of a user table which are located near to the ZIP „47551“.
Of course exact matches must be on top:

SELECT name,zip,city FROM user
WHERE zip BETWEEN 47500 AND 47599
ORDER BY (zip = 47551 ) DESC , (zip LIKE '4755%' ) DESC, (zip LIKE '475%' ) DESC , zip DESC

Unsere Partner