There are three tables - Item , Detail and DetailsItem . Between themselves, they create a many-to-many connection. How can I implement Item Search on defined Detail .
For example, there is a hammer . It consists of several parts, such as: iron , wood , copper . I need to find this hammer in detail. For example, I drive in parameters such as wood and copper which will exactly find the desired element, but if I add an additional parameter such as silicone , then this element is discarded.
Also, according to these parameters, there may be other elements that contain iron, wood and copper, but if one of the parameters does not match, then the element should not be displayed in the final sample.
SELECT item.idItem, detail.idDetail, detail.title FROM item JOIN details_item ON item.idItem = details_item.idItem JOIN detail ON detail.idDetail = details_item .idDetail WHERE detail.title in ("Железо","Дерево","Медь") This query finds the elements in which there are these parts, but other elements are also displayed, which have only 1 of 3 materials matching.
It is also not known in advance how many parameters there will be for searching, since an array will be passed to in (...)