title: SQL get parent row if child rows match multiple conditions
body: <p>I have a properties table that has:</p>
  
  <p><code>parent_record_id</code>(which record the property belongs to), </p>
  
  <p><code>property_type_id</code>(what is the name of the property) and</p>
  
  <p><code>property_value</code> for that property. </p>
  
  <p>Now I have a <code>property_type</code> that's called <code>DATE</code> and another <code>property_type</code> that's called <code>PRICE</code>. When I want to search for records that have a </p>
  
  <p><code>PRICE = 50$ OR DATE = 2016-10-02</code> </p>
  
  <p>it performs as expected. Yet the client requires to be able to retrieve records that have a <code>PRICE = 50$</code> and have also been sold on <code>DATE = 2016-10-02</code>. So in essence I have to get the records if two of their children meet either </p>
  
  <p><code>(property_type = PRICE AND property_value = 50$) OR (property_type = DATE AND property_value = 2016-10-02)</code></p>
  
  <p>I guess the straightforward approach would be to just perform that query in SQL and then <code>GROUP</code> the records and check if <code>SUM</code> of properties <code>= 2</code>. (0)</p>
  
  <p>I have also, upon traversing the cyberspace, found that another way to slay the proverbial dragon is to JOIN the properties table two times(in the context of this example) assigning different aliases each time and then perform both queries on those aliased tables. (1) <s>The result has pleased me to a great extent.</s> </p>
  
  <p>The (0) solution seems wasteful since it would keep checking if rows meet the conditions even after one of them has been proven to be false(and since every record might have up to 20 of these property/value pairs the table is going to be huge).</p>
  
  <p>UPDATE: Now that I've thought about it more (1) would probably have the same drawback and also check the same row twice.</p>
  
  <p>What about the (1)? Are there any other possibilities to solve this problem. Also how performant are both of these solutions in comparison? </p>
  
  <p>(and yes I know that modeling the properties in this way, especially on tables, is going to be a headache in the future anyways, but RDBMS is what I have to work with and this solution seemed flexible enuf given the current situation) </p>