sql - mysql select rows on comma seperated value in column -


i've product table 3 columns:

  1. product_id
  2. product_name
  3. 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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -