So I’m trying to search through a column where the string is a comma separated list of words with no spaces such as one,two,three,four and so on. Problem I’m facing is that I’m trying to match an exact word in the string. As of now I’m simply using %word% to find a match which of course works but the problem is it isn’t exact in that if I searched for ‘word’ it would also match ‘words’, ‘worded’ and so on. So question is how can I search and get the exact word?
Share
Append and prepend a comma to the string value in the column and then search it for your term which also has comma on either side of it:
becomes
and you search for
You don’t have to alter (“tamper with”) the database record itself.
P.S. Wildcard on both sides of search term eliminates possibility of using an index to speed the search, so this approach is not recommended on large datasets. But then again, neither is a comma-delimited list 🙂
P.P.S. I don’t know what device you’re using, of course, or the size of your table, but on a PC several years old it takes SQlite 8ms to search through 3000 records using this comma-concatenation approach.