Search code examples
iossqlfmdbfind-in-set

FMDB Database Query IOS FIND_IN_SET()


I am using FMDB database in IOS. In my database I have a one column called tags. Tags column have a comma separated Value like apple,banana,. I want Title column where my keyword matches. I want to know how to search comma separated value in table column Please help.


Solution

  • You need to use LIKE operator, when you have a field data like apple,banana,... you can add a , at the beginning and end of it like ,apple,banana,..., that makes all tags between two commas. Now you can check it if it contains ,yourTag,.

    I'm not so familiar with FMDB, But I think below code can help you:

    FMResultSet *rs = [db executeQuery:@"SELECT Title FROM yourTable WHERE ','+tags+',' LIKE ?",
                      [NSString stringWithFormat:@"%%%@%%", @"," + search_text + @","]];