I have the following data.
ID | heade |
---|---|
100 | blue |
100 | black |
100 | orange |
101 | brown |
101 | green |
102 | green |
102 | white |
102 | yellow |
103 | yellow |
103 | blue |
Intended results: If I select blue, I want to get 100 and 103. If Select blue and yellow return only 103. if I select blue yellow and white, no results should be returned. Basically I want to get only the PID columns that match all the selected colors.
NB: the IN SQL statement will only give me PID that contains any colors mentioned in the statement. I need my criteria to be met as explained above. Let me have have your thought. I’m open to all suggestions even if the solution will involve a combination of sql query for the initial results, and then a json object to filter as required
I have tried the IN in the WHERE predicate clause but this only gives me PID that match any colors in the statement
2
Answers
This can be generalised as :
You can pass the exact colors and their count as ‘n’. Here is a DBFILLDLE demo.
When you pass three colors :
Outout : Empty.
When you pass two colors :
Output :
When you pass single color :
Output :