I am trying to do something similar to a column intersecting on two tables. Tables:
LogTag: a log can have zero or more tagsMatchingRule: a matching rule consists of one or more tags that define a rule
Zero or more rules can be set in a log. I will go through MatchingRuleIDand expect to return all journals that comply with this rule.
Expected Result: A set of results for matching LogIDs. For example. transmission MatchingRuleID = 30must return LogID101. MatchingRuleID = 31must return LogID101 and 100.
In addition, a table LogTagcan have millions of rows, so the preferred efficient query is.
Question: How do I find all LogIDthat match a given rule definition?

Scheme:
CREATE TABLE dbo.Tag
(
TagID INT,
TagName NVARCHAR(50)
)
INSERT INTO dbo.Tag (TagID, TagName)
VALUES (1, 'tag1'), (2, 'tag2'), (3, 'tag3')
CREATE TABLE dbo.LogTag
(
LogID INT,
TagID INT
)
INSERT INTO dbo.LogTag (LogID, TagID)
VALUES (100, 1), (101, 1), (101, 2), (101, 3), (101, 4), (102, 2), (102, 3)
CREATE TABLE dbo.MatchingRule
(
MatchingRuleID INT,
TagID INT
)
INSERT INTO dbo.MatchingRule (MatchingRuleID, TagID)
VALUES (30, 1), (30, 2), (30, 3), (31, 1)