I want to search the styleID and colorID fields on multiple inputs. For example I’d like to search the table where styleID = 3, styleID = 4, colorID =1, colorID = 5 and then group those results by boxID. Ordering the results by the number of actual matches within that group.
A boxID that contains a styleID of 4 and styleID of 3 and colorID of 1 and colorID of 5 would show first as it matches all the criteria.
ID boxID styleID colorID keywords
1 1 4 1 Sexy Tie
2 1 3 2 Red Tie
3 1 3 6 Striped Blue
4 2 3 2 Checkers
5 2 3 5 It's not blue
6 2 4 6 Cyan is purple
7 3 4 2 Fancy
8 3 4 5 Fancy
9 3 4 2 Fancy
You could try something like that
http://sqlfiddle.com/#!2/b5879/20