sql - mysql select rows on comma seperated value in column -
i've product table 3 columns:
- product_id
- product_name
- product_keywords
and contains values that:
product_id | product_name | product_keywords
1 |computer |pc, computer, laptop, personal computer, desktop computer
------------------------------------------------------------------------------------------------------------------'
2 |mobile |smart phone, phone, nokia, sony
--------------------------------------------------------------------------------------------------------------------'
now need sql query if customer search pc or personal computer return product_name = computer product_id = 1 , on.
although first instinct re-design schema have keywords
table unique values , mapping table between products , keywords, mysql offers elegant way query comma-delimited strings find_in_set
function:
select product_id, product_name products find_in_set ('pc', keywords) > 0 or find_in_set ('personal computer', keywords) > 0
Comments
Post a Comment