I have fetching record from table named Pizza_Table.
Pizza_table Schema
id | pizza name | pizza_topping_ids
1 | pizza1 |1,2,3
2 | pizza2 |2,3
3 | pizza3 |4,5,6
Actually my functionality is searching pizza based on pizza_topping_ids
I have work allot in this searching. but I can’t find proper solution. .
I can’t use IN clause for fetching record.
I have tried out :
1)
SELECT *
FROM `pizza_table`
WHERE `pizza_topping_id` REGEXP '[[:<:]]2[[:>:]]'
Problem : fetch all record having value 2
2)
SELECT *
FROM `pizza_table`
WHERE `pizza_topping_id` REGEXP '[[:<:]]1,2,3,4[[:>:]]'
but MySQL returned an empty result set,
If comma separated values are not match to any record then return result which is most having value in topping_id column.
EX: If i have run above query for find out pizza having 1,2,3,4 topping_id, but In database no pizza exist having such topping_id combination then result will be most covered id should be displayed like ‘pizza1’ having pizza_topping_id 1,2,3.
Sorry for bad English as well as format, but try to understand my problem.
Thanks in advance.
Please help me.
Just try this-
OR REGEXP
Please see the demo : demo