I have three tables:
items:
id name
4 Item Blue, L
2 Item Blue, S
6 Item Green
8 Item L
9 Item Red, Blue, Green, S, M, L
5 Item Red, L
3 Item Red, M
1 Item Red, S
7 Item S
options:
id group name
1 1 red
2 1 blue
3 1 green
4 2 s
5 2 m
6 2 l
items_has_options:
item_id options_id
1 1
1 4
2 2
2 4
3 1
3 5
4 2
4 6
5 1
5 6
6 3
7 4
8 6
9 1
9 2
9 3
9 4
9 5
9 6
How can i select items which have options: (red or blue or green) and (s)? I need to choose items which have some options from different groups. Options may have many groups, not only two. Result must be:
2 Item Blue, S
9 Item Red, Blue, Green, S, M, L
1 Item Red, S
Not sure this will work but it might get you started..
The idea is that you join with the options table twice, once for color and once for size.
You need the distinct since you will get duplicate rows from o1…