SQLite doesn’t have a FIND_IN_SET
operator to test whether or not a string exists in set value. To work around it, you can do string comparison using LIKE
.
However, to handle all cases of a string in a comma joined array of strings (e.g. a collection of tags related to a post aggregated using GROUP_CONCAT
) you need to prepare the value by adding preceding and trailing commas.
For example:
select * from (select post_id, group_concat(tags.tag) as alltags from tags group by tags.post_id) where ','||alltags||',' like '%,food,%';
This returns the correct result whether the food
tag was first, last, or somewhere in the middle.