How to Do A Database Count Through Records Containing Comma Separated Values?

I have a table of contacts, which have a field called contact_tags. Each tag recorded is the id from the table lookups.

To keep things (possibly) easy, for each contact I’m just storing the contact_tags as a comma separated string.

So some lookups records may be:

id     lookup_name
==================
100    Rock
101    Country
102    Classical
103    Funk

and some contacts records may look like:

id   name   contact_tags (string)
=================================
1    Fred    100,101
2    John    102,100,103
3    Jane    103

I want to count the number of contacts who have the tag of Rock.

Do you know a neat way I can do that within a Server Action?

Community Page
Last updated: