Tables
product: id, price
productattribute:id, productid, attributeid
attributes: id, value, attributetypeid
attributetype:id, name
Query
select p.Name, p.Price, att.Id, att.Value, at.Id, at.Name
from Product p
inner join ProductAttribute pa on pa.ProductId = p.Id
inner join Attributes att on att.Id = pa.AttributeId
inner join AttributeType at on att.AttributeTypeId = at.Id
Result
Name Price Id Value Id Name
Slr camera 90 1 White 1 Color
digital camera 98 2 Black 1 Color
Slr camera 90 4 big 2 Size
digital camera 98 5 medium 2 Size
Now I want to retrieve products by filtering attributesid ie attributesid=1(which is white) and doing so must filter only the color attributetype not the size. What I mean is it should retrieve three rows now: rows with Color – White, Size – big and Size – medium.
Use a
whereclause to allow non-color attributes and color attributes if they’re white: