I have a table like below
============
item | tag
-----+------
111 | amaretto
-----+------
111 | blueberry
-----+------
222 | amaretto
-----+------
333 | blueberry
-----+------
333 | chocolate
-----+------
444 | chocolate
-----+------
444 | amaretto
-----+------
555 | chocolate
-----+------
666 | blueberry
-----+------
666 | amaretto
-----+------
666 | chocolate
============
The columns item
and tag
together constitutes a composite primary key. Lets imagine like the the item as an ice cream and the tags as the available flavors. For example, if I search for amaretto (in the case of ice cream), I want to display all possible combinations in which amaretto ice cream is available, like amaretto, amaretto+chocolate, blueberry+amaretto etc. If I search for tag amaretto
, I want to display all possible combinations like;
amaretto (222)
amaretto,blueberry (111)
amaretto,chocloate (444)
amaretto,blueberry,chocolate (666)
And the combinations amaretto,blueberry
and blueberry,amaretto
are same.
How can I do this? Do i need additional tables? I use PHP+MySQL.