Short term solution
Use the FIND_IN_SET function :
WHERE FIND_IN_SET('Queensland', csv_column)
... because using LIKE with wildcards at both ends is risky, depending on how many / small matches (and also provides table scans). LIKE performance with wildcards on both sides is on par with REGEXP - which means it's bad.
Long term solution
Do not store values โโseparated by commas - use the correct many-to-many relationship with three tables:
Things
Australian states
- State_id (primary key)
- State_name
Things_to_Auz_States
- thing_id (primary key, foreign key for table
THINGS ) - State_id (primary key, foreign key for table
AUSTRALIAN_STATES )
You will need JOINs to retrieve data from three tables, but if you want to find out how many of them are related to a particular state or two specific states, this is the correct model.
OMG Ponies Oct 04 2018-10-10T00: 00-10
source share