Let's say you have the rule table :
Rule
Id--Color--Size
1 --blue -- null
2 --blue -- 15
And Entry table
Entry
Id--Color--Size
1 --blue -- 10
Put a null value instead of a 'Any' value to keep some strong typing
A solution :
Select r.id as rule_id,
e.id as entry_id
From Entry e inner join Rule r
On (e.Color = r.Color or r.Color is null)
And (e.Size <= r.Size or r.Size is null)
You can create a new table Color for better performance :
Color
Id--Name
1 --Red
2 --Blue
Rule
Id--Id_Color--Size
1 -- 2 -- null
2 -- 2 -- 15
Entry
Id--Id_Color--Size
1 -- 2 -- 10
Select r.id as rule_id,
e.id as entry_id
From Entry e inner join Rule r
On (e.Id_Color = r.Id_Color or r.Color is null)
And (e.Size <= r.Size or r.Size is null)
Add an index to both Id_Colors