例子:
商品表:product 字段:rid(int) name(nvarchar)
rid name1 a
2 b
3 c
商品属表 Proattr 字段rid(int) TypeID(int)
rid TypeID
1 1
1 2
2 1
2 3
3 5
3 4
求商品属性满足1,2的商品
sql:
select * from product where exists (select1 from Proattr where Proattr.rid=product.rid and Proattr.TypeId=1) and exists (select 1 from Proattr where Proattr.rid=product.rid and Proattr.TypeID=2)