Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4327668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:34:16+00:00 2026-05-21T09:34:16+00:00

I’m having the following situation: I have a table with a list of postcodes

  • 0

I’m having the following situation:

I have a table with a list of postcodes with the format:

1234 AA (Dutch postcode)

2345 ZF

B-2345 (Belgium postcode)

B-4355

I have another table which contains postcoderanges:

PostcodeFrom

1000 AF                     
2000 ZF
B-1234

PostcodeTo

1999 ZX
2999 ZF
B-1889

I am looking for a solution how to look up the postcode value between the several ranges.
First I was thinking of

SUBSTRING(MyPostcode,1,4) BETWEEN SUBSTRING(PostcodeFrom,1,4) AND SUBSTRING(PostcodeTo,1,4)

.. but then there is still the problem with the characters (not even thinking about the belgium postcodes aswell).

Could anyone help me?

Yours,


Thanks for your reply!

The table you drew, needs one more field: RegionCode.

RangeTable:

| RCode | PCodeFrom | PCodeTo |
| 001 | 1000 BA | 1999 ZZ |
| 002 | 1000 AA | 1999 AZ |

Notice that if a postcode is 1234 AC, it must return RegionCode: 002
To compare numbers is not hard, but how to compare characters?

I had an idea of making a table with AA – ZZ where each combination has a certain INT value, but I hope there is another, easier way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:34:17+00:00Added an answer on May 21, 2026 at 9:34 am

    You can only do this reliably (ignoring the potential un-reliability of doing this sort of range matching with postcodes) by splitting the portions of the postcode into different columns by character type.

    I don’t know much about Dutch postcodes, but if your formats are correct, you could create a table like:

    +-------+------+
    | code  | city |
    +-------+------+
    | 1234  | AA   |
    +-------+------+
    

    Splitting the postcodes up will allow you to do more fine-grained sorting.

    Update:

    Having looked at the Wikipedia page on Dutch postcodes it looks like this should work for all of them. My labels of code and city are inaccurate though.

    Aside: I’m impressed that the Netherlands has such a sane postcode format, unlike the UK one where you need a huge regex to even decide if the format is valid.

    Update 2:

    Your checking will work with characters too, but you’ll be better off storing the postcodes in a separate table, with an ID. The example above was just to show splitting up the characters from the numbers, so what you’ll actually want is more like:

    mysql> select * from postcodes;
    +------+-------+-------+
    | id   | part1 | part2 |
    +------+-------+-------+
    |    1 |  1234 | AA    |
    |    2 |  5678 | BB    |
    +------+-------+-------+
    

    When you’re storing the ranges, don’t store the postcodes in the ranges table, store the id for the entry in the postcodes table, like:

    mysql> select * from ranges;
    +-------------+---------------+-------------+
    | region_code | postcode_from | postcode_to |
    +-------------+---------------+-------------+
    |           1 |             1 |           2 |
    +-------------+---------------+-------------+
    

    That record says “region 1 is 1234 AA to 5678 BB”

    For an example, I’ll say that postcodes start 0001 AA, then move to 0001 AB, all the way to 0001 ZZ, then 0002 AA and so on. This obviously isn’t right but it demonstrates the theory. You need to substitute this for the algorithm you’re using to define how postcodes are incremented and decremented.

    When you want to find out “does postcode 3456 XY fit into region 89?”, you split it into character and number, and check whether the values fit into a range. Using my algorithm, I check:

    Is the number portion greater or less than the number portion of postcode_from?

    If it’s greater, then is it less than the number portion of postcode_to?

    If you satisfy both conditions, check the letters – this is the important bit – MySQL’s character set collation does allow you to say “is AB less than BC, you can have:

    WHERE 'AB' < part2;
    

    in your WHERE clause.

    Using this method, you can figure out which of your regions has a start and an end that fit the value you’re testing.

    It’s a bit long-winded but it will work without doing any conversions. You may need to check that the collation you’re using fits the way the lettering sequence works for the specific type of postcode you’re using though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.