title: PostgreSQL. Search for a value through a list of attributes with a specific id
body: <p>I need to make search for an object by specific attributes. I have a table item_attribute:</p>
  <blockquote>
  <h3>item_attribute             item_attribute_type_fk            item_fk              value_text</h3>
  <pre><code>     1                        1                   1              bbbb
       2                        2                   1           450-240-310
       3                        3                   1             800x250
       4                        4                   1               2,2
       5                        1                   2               HBO
  </code></pre>
  <p>etc</p>
  </blockquote>
  <p>I've tried this:</p>
  <pre><code>SELECT item,name,sale_price,producer,producer_code,store_price,I.type_name 
  FROM ((item INNER JOIN unit_type ON unit_type_fk=unit_type) 
  INNER JOIN item_store ON item=item_fk)AS I 
  INNER JOIN item_attribute AS A ON I.item=A.item_fk 
  WHERE store_price BETWEEN 200.0 AND 300.0 
  AND (UPPER(value_text) LIKE UPPER('%b%') AND item_attribute_type_fk=1) 
  AND (UPPER(value_text) LIKE UPPER('%2%') AND item_attribute_type_fk=4) 
  GROUP BY item,I.type_name ORDER BY item
  </code></pre>
  <p>Result should be row, where item_fk = 1, but in reality select returns zero rows. If I change <code>AND</code> to <code>OR</code> between attributes that will result in several rows, which is not exactly what I want, because search need to return only that object, that has <b>all</b> attributes, that user typed in in search field. How should I change code, that it will look for a value only through attributes with specific item_attribute_type_fk and return row with object, that has all that attributes?</p>