I have three tables; StoreAttributes
and TemplateCondtions
are both connected in a 1-to-many relationship with the ConditionAttributes
table.
ConditionAttributes
PK CondiitionAttributeId int
Name varchar(100)
StoreAttributes
PK Id uniqueidentifier
StoreNbr string
ConditionAttributeId FK (From Condition Attributes)
TemplateConditons
PK Id uniqueidentifier
TemplateId uniqueIdentifier
ConditionAttribureId FK (From Condition Attributes)
Example data set:
StoreNbr WalkConditionAttributeId
------------------------------------
5705 1
5705 2
5707 2
5705 3
5706 3
Id TemplateId WalkConditionAttributeId
--------------------------------------------
105 78 1
109 78 2
500 78 3
I’d like to select only store 5705 because it matches all WalkCondtionsAttributeId
for TemplateId = 78
.
So far I’ve tried this:
Select Distinct StoreNbr
From StoreAttributes st
Where WalkConditionAttributeId in (Select ConditionAttributeId
From TemplateConditions
Where TemplateId = 78);
This returns the wrong StoreNbr
because they contain at least one row in the TemplateConditions
table.