For a application I'm currently developing I have a little problem that needs to be fixed, it is oriented for the Dutch so I have a table of all the Dutch zip codes that I can use.
In my application I need to build regions based on cites and this is where I hit a problem, currently I select the first and last known zip code of a city, which is fine in most cases. Which is fine for most cases, but sometimes this doesn't work right because of a zip code being numbered before another city, so that means that in some cases one city matches another.
What I would like to do is get all the ranges with my city from my table. This is a little example what the table looks like (it is missing some unneeded fields for this porpuse).
Zipcode | City
--------|-------
2411 AA | Bodegraven
2411 AB | Leiden
2411 AC | Leiden
2411 AD | Bodegraven
2411 AE | Bodegraven
2411 AF | Leiden
2411 AG | Leiden
2411 AH | Bodegraven
With my current query the first zipcode in Bodegraven would be 2411 AA and the last 2411 AH, which isn't interly incorrect, since that is what is stored. However I would like my result to be the following:
Start | End
--------|--------
2411 AA | 2411 AA
2411 AD | 2411 AE
2411 AH | 2411 AH
Is it possible with pure MySQL to generate this result?
Thank you for your time, and responses, if you have any questions please let me know :)