Hi guys, just wondering if there were any sql gurus in here, I have a small problem that I'm stumped on...
OK basically I'm making an anagram solver... I put in an anagram e.g. 'odg' and it tells me things that match: 'dog', 'god'.
In order to do this I'm ordering the strings alphabetically and comparing them.
so:
odg >> dgo
dog >> dgo
god >> dgo
and then you can easily see if they match....
in order to make this run faster I want to have an 'anagram' column in the database with the word pre sorted.
I am currently trying to do this in PHP with a loop which goes through each row, sorts the word, then does an update statement to enter the anagram in.
However the DB has 750k words in and this is incredibly slow. Is there any way to do this in pure SQL for more speed?
The current sorting algorithm is like so: implode(sort(explode($word))). as far as I know SQL doesn't have any similar functionality.
This is MySQL btw.
Cheers!
Hamish
OK basically I'm making an anagram solver... I put in an anagram e.g. 'odg' and it tells me things that match: 'dog', 'god'.
In order to do this I'm ordering the strings alphabetically and comparing them.
so:
odg >> dgo
dog >> dgo
god >> dgo
and then you can easily see if they match....
in order to make this run faster I want to have an 'anagram' column in the database with the word pre sorted.
I am currently trying to do this in PHP with a loop which goes through each row, sorts the word, then does an update statement to enter the anagram in.
However the DB has 750k words in and this is incredibly slow. Is there any way to do this in pure SQL for more speed?
The current sorting algorithm is like so: implode(sort(explode($word))). as far as I know SQL doesn't have any similar functionality.
This is MySQL btw.
Cheers!
Hamish