I have a string array comprised of words (ex. { alpha, beta, gamma } ) and a MySQL table filled with words. For each string array, I come up with a SELECT statement that queries the MySQL table to see if there are any matches of words. The rows that are returned let me know when a word in my string array is one of the unique ones in the table. I then alter the text of the specific string in the string array. For simplicity sake, let’s assume I want to call a .ToUpper() on it.
My current method is to get all of the rows from the table that match and then loop through the string array and check whether every single row returned matches every single string in the array. That’s incredibly inefficient, and I would much rather have the rows returned from my MySQL query have a column that tells me which position in the string array that word came from. That way I can jump right there and fiddle around with the string. Is there a way to give each “LIKE” clause in the where statement a unique identifier that is returned if that specific like clause is the one that matches? Any ideas would be much appreciated.
My Select Statement is:
SELECT `WordText` FROM `Words` WHERE `WordText` LIKE 'alpha%' OR `WordText` LIKE 'gamma%';
What I am looking for is something like this:
SELECT `WordText`, PositionInArray FROM `Words` WHERE `WordText` LIKE 'alpha%' (IF MATCH THEN PositionInArray=0 -- alpha's position in my array) OR `WordText` LIKE 'gamma%' (IF MATCH THEN PositionInArray=2 - gamma's position in my array);
When this row is returned, I can go straight to WordArray[PositionInArray].ToUpper() and know that that is the word that matched.
Thanks a lot!
1 Answer