Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#258613 - 21/06/2005 09:00 Searching for MySQL-Statement...
Happy Birthday rowitech
enthusiast

Registered: 22/09/2002
Posts: 249
Loc: Germany, Cologne
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)

Top
#258614 - 21/06/2005 17:41 Re: Searching for MySQL-Statement... [Re: rowitech]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Would
Code:
WHERE "49210491" RLIKE CONCAT("^", pattern)

work?
_________________________
Bitt Faulk

Top
#258615 - 22/06/2005 03:43 Re: Searching for MySQL-Statement... [Re: wfaulk]
Happy Birthday rowitech
enthusiast

Registered: 22/09/2002
Posts: 249
Loc: Germany, Cologne
Perfect!

That's exactly what I searched for. I didn't now that concat even works this way, I'm surprised.. Thank you very much.

regards
Rolf
_________________________
Connecting Empeg via Bluetooth or Wireless LAN http://empeg.rowi.net
*** Proud owner of the European Worst Install Trophy 2003 ! ***
RoWi

Top