Forum Moderators: coopster
i am writing a simple search using the levenshtein() function. this is returning an array of nearly-matching IDs which i am using to search the database.
is there any way i can order my select statement in the same way which the levenshtein array is ordered?
at the moment my (simplified) sql is:
SELECT ID, title
FROM table
WHERE ID IN($my_imploded_levenshtein_array)
however, this is ordered normally by ID, instead of the same order the levenshtein array is in.
i had thought of creating a temporary table for all the data, but as i am selecting data from 3 joined tables, i think this would be a bit cumbersome.
cheers
not to worry, i too have been going round in loops this morning, thinking about how to sort them using php - but as you say, all a bit inelegant ;-)
i then thought to create a temp table holding the correct order and join it to the other tables and use it to ORDER BY, but i am unable to join a temporary table to a real table.
hmmmm...
thanks for input anyway
How to make MySQL return an pre-ordered list [webmasterworld.com]
for the page as a whole, using coopster's ORDER BY method is on average 0.004 seconds quicker.
i haven't however, broken the page into individual queries and tested those.
i suspect the time difference on the page as a whole is due to the INSERT INTO TempTable operations (there are 8). this would mean that the join on the temp table is indeed quicker than the multiple ORDER BY's. i'll remember that thanks.
SN