I have a database that lists a few area codes, area code + office codes and some whole numbers and a action. I want it to return a result by the digits given but I am not sure how to accomplish it. I have some MySQL knowledge but its not very deep.
Here is a example:
match | action
234 | goto 1
333743 | goto 2
8005551212| goto 3
234843 | goto 4
query 8005551212 gives "goto 3"
query 2345551212 gives "goto 1"
query 3337431212 gives "goto 2"
query 2348431212 gives "goto 4"
SELECT * FROM database WHERE `match` = 8005551212;
SELECT match, action FROM mytable WHERE '8005551212' like concat(match,'%')
The issue is that you will get two rows in one case .. given your data..
SELECT action FROM mytable WHERE '8005551212' like concat(match,'%') order by length(match) desc limit 1
That should get the row that had the most digits matched..