help building a mysql search query
Hi,
I need to build an SQL search query to find a row that is the longest part of the start of another string.
e.g.
search string - "helloworld"
rows in database
hellowo
elloworld
I would need it to match hellowo.
My current query I'm runing is..
select * from list where helloworld RLIKE list ORDER BY LENGTH(list) DESC
However, this would actually match "elloworld" as the first result. I need the query to return only results that start as the search string, not just contain it.
Can anybody point me in the right direction?
I have tried running a query for an exact match, and if it doesn't find one, it knocks a character off the end and re runs it. This works but makes the script run very very slowly and hammers my CPU.
Last edited by Rickead2000; 10-16-2007 at 05:05 AM.
|