Reverse pattern matching: find the longest prefix I have a database with the phone rates. Rather simple one.

Code     Price
----     -----
1        0.005
18       0.002
1888     0.000


Now I have a phone number arriving to the database: 18127551221. I want to do a query and get the price of the call.

I want to be able to find longest possible match in the "Code" column. Length of the Code can be up to 6 symbols so I want something versatile.

Any ideas?
Something like this should work:

SELECT *  
FROM prices  
WHERE '18127551221' LIKE "Code" || '%'  
ORDER BY "Code" DESC 
LIMIT 1