I've tried a few ways to achieve what's next but there's got to be an easy way.
Assuming I have cooking recipes. Each recipe has ingredients. When workers prepares a recipe, they do so in multiples batches.
I'm trying to figure out how to find the batches that are missing which ingredient to insert into another table later on, which has all the preparation data. Currently, it only shows the data for ingredients that were actually used.
Here's the data:
CREATE TABLE #Repipe
(
Recipe VARCHAR(1)
, Ingredient VARCHAR(2)
)
INSERT INTO #Repipe (Recipe, Ingredient)
VALUES
(1, 1)
, (1, 2)
, (1, 3)
, (1, 4)
CREATE TABLE #RecipePreparation
(
Recipe VARCHAR(1)
, Batch SMALLINT
, Ingredient VARCHAR(2)
)
INSERT INTO #RecipePreparation (Recipe, Batch, Ingredient)
VALUES
(1, 1, 1)
, (1, 1, 2)
, (1, 1, 3)
, (1, 1, 4)
, (1, 2, 1)
, (1, 2, 2)
, (1, 2, 3)
, (1, 2, 4)
, (1, 3, 1)
, (1, 3, 3)
, (1, 3, 4)
DROP TABLE #RecipePreparation
DROP TABLE #Repipe
As you can see, the batch number 3 is missing ingredient #2.
