Hi,

I want to search for a matching number in a database.
It should match only from the beginning, not inside the string.
My problem is that I cannot just add a ^ sign before the "pattern" because it's the name of a field in the database.


Example:
Code:
mysql> SELECT * FROM routes WHERE "49210491" RLIKE pattern ORDER BY LENGTH(pattern) DESC;


+---------+----------------------+---------+-------------+-----------------+--------+
| pattern | comment | trunks | connectcost | includedseconds | cost |
+---------+----------------------+---------+-------------+-----------------+--------+
| 491 | Sondernummern | | 0 | 0 | 900000 |
| 49 | Festnetz Deutschland | nikotel | 0 | 0 | 200 |
+---------+----------------------+---------+-------------+-----------------+--------+



I want the function to give me the longest matching pattern. Currently it gives back 491also due to the pattern _inside_ the string. In this example best match would be just 49.

Hope you know what I'm trying to say.

Rolf

edit : Formatted text
--l0ser


Edited by l0ser (21/06/2005 14:59)