Hi bunwong,
do you have a field on "dialed_digits" holding the number of digits?
I'm assuming that this table holds records like 1, 12, 123, etc?
Then if you have a column (e.g. highest_match) to hold 1 for 1, 2 for 12, 3 for 123, etc you should be able to use somthing like this
select...