I have a database and some of the columns contain things like CA, GB etc, although some contain multiple country codes like
US+GB+CA+AU
I’m just wondering what kind of query I would do that would return that row when I’m searching for just CA or just GB, and no necessarily the whole package US+GB+CA+AU
Encase that’s a little confusing, basically I just need to return that row based on a search for just CA or just GB etc.
Thanks
Use
FIND_IN_SET(), but you’ll first need to replace+with,since it expects a comma-separated string. Even without theREPLACE(), this is will not make use of any index on the countrycodes column.The proper long term solution, however, is to change your database structure to normalize these country codes into a table that contains only two columns – a country code, and the id of the associated row from the table you’re attempting to query now. You can then index the column appropriately to improve performance (possibly drastically improve it).