There are 3 tables: Products, attributes, id attribute values ​​are known. You need to output products according to certain attribute parameters.

$sql = "SELECT g.id, g.title FROM goods g LEFT JOIN attr_values attr_v ON g.id = attr_v.id_goods WHERE ( ((attr_v.id_attr, attr_v.value) = (1, 'параметр...')) AND ((attr_v.id_attr, attr_v.value) = (2, 'параметр...')) ) "; 

As a result, I get an empty result = ((What is the problem and how can I rewrite the request, preferably for working with a large amount of information Thanks in advance

Reported as a duplicate by members of BOPOH , aleksandr barakin , ka5itoshka , Shilgen , PloadyFree Aug 26 '15 at 18:39 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • AND is И , how can an attribute have an id equal to both 1 and 2? OR must be used - BOPOH
  • one
    Possible duplicate question: Several AND in MYSQL query - BOPOH
  • You probably did not understand the meaning of the whole task, if you put the logic OR. I agree everything will work, but the request will return incorrect data. If we put OR then the result will give the goods in which there is for example the first parameter but no second - bajor
  • Yes, he was wrong. This is a duplicate of another question - BOPOH
  • 2
    Possible duplicate question: Selection of records that simultaneously have several values - ka5itoshka

0