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 3226322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:26:32+00:00 2026-05-17T16:26:32+00:00

I am looking up which exchange services which telephone numbers, from a table of

  • 0

I am looking up which exchange services which telephone numbers, from a table of fragmentary numbers that show which exchange services them.
So my table contains, for example:

id      |exchcode   |exchname       |easting|northin|leadin     |
-----------------------------------------------------------------
12122   |SNL/UC     |SANDAL        |43430   |41306  |1924240    |
12123   |SNL/UC     |SANDAL        |43430   |41306  |1924241    |
881     |SNL/UD     |SANDAL      |43430 |41306  |1924249    |
2456    |BD/BCC/1   |BRADFORD CABLE |41627  |43262  |192421     |
4313    |NEY/UB     |NORMANTON      |43847  |42289  |192422     |
12124   |SNL/UC     |SANDAL         |43430  |41306  |192425     |
9949    |OBE/UB     |HORBURY OSSETT  |42857 |41971  |192428     |
9987    |OBE/UB     |WAKEFIELD       |42857 |41971  |1924       |

(sorry, formatting a bit rubbish)

leadin is the leading part of the phone number I have to match (stored as a VARCHAR, not a number)

And I am supplied with a phone number 1924283777 (not real)
how do I query to get the best match from the above table (It should pick exchange id 9949), or do I deal with it in code after I’ve done the query (php)

tl;dr: variable length for values of leadin column, want best match with a number longer than leadin.

  • 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-17T16:26:33+00:00Added an answer on May 17, 2026 at 4:26 pm

    I would think something like

    WHERE ? LIKE concat(leadin, '%') order by length(leadin) desc limit 1
    

    (I haven’t checked the function names, and I’m not certain that this will work in MYSQL – I’m pretty sure it will work in one of the SQL’s I’ve used).

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

Sidebar

Related Questions

Hi I'm looking for a WCF example which include service discovery and a way
When looking for which version of Delphi 2010 to buy, we found the following
I'm currently looking at which build server we should run up for a multi-platform
I have a class in which looking up an instance is expensive, so instances
I am looking at code which has the correct using statements declared but yet
I'm a student looking for resources which can help me further understand how to
Video podcast ??? Audio only mp3 player I'm looking for somewhere which will extract
Does anyone know of any C container libraries? I am looking for something which
Looking for C# class which wraps calls to do the following: read and write
Which of the new features are you looking forward to the most in iPhone

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.