I have a field in my database that contain comma separated values these values are numbers, and I am trying to do a search and count the number of times that a number appears in that column throughout the column,
$sql = "SELECT sector_id_csv, COUNT(sector_id_csv) as count FROM cv WHERE sector_id_csv LIKE '$sectorId'";
This seems slow and does not return any results, and I know the sector_id it is search exists in the table.
Basically, this should work fine if you use
%wildcards:what tends to cause problems in this scenario, though, is the fact that a search for
50will also find501502503and so on.If you can rely on your comma separated list to have a trailing comma behind every entry, it would be more reliable to search for
50,to catch that value only.