I have a recipe table that is structured like this:
product2recipe
id | productid | recipeid
I want to eliminate insertion of duplicate values. Basically a recipe can contain 1 or more productid. So it looks like this:
1 | 1 | 1
2 | 2 | 1
3 | 1 | 2
4 | 5 | 3
The user can submit a new recipe, if the recipe contains similar value like:
id | 1 | 4
id | 2 | 4
Then it should not submit, because the table already have duplicate values, recipeid 1 contains productid 1 and 2 already. If it is:
id | 1 | 5
id | 3 | 5
Then it should submit since this is a unique combination.
How can I query my table optimally? I'm afraid that it might stall my database server since there's possibly many combinations.