Answer the question
In order to leave comments, you need to log in
How to form a correct query in a linked table?
Let's say there are 3 tables: Products, Attributes, Attribute_values (linked to the other two by attribute/product_id).
There are 2 products - Computer chair and Armchair
There are 3 Attributes - Backrest, Armrests, Adjustable height.
And the question is: How to pull out products that have all 3 attributes available (= 1) through an adjacent table? (only a computer chair should turn out)
Answer the question
In order to leave comments, you need to log in
Like this, for example (this is T-SQL):
select P.*
from Products as P
join Attribute_values as AV
on AV.ProductID = P.ID
and AV.Value = 1
and AV.AttributeID in (attr1, attr2, attr3)
group by P.*
having count(AV.ID) = 3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question