title: Mysql Complex Where Clause
body: <p>I really surprised when I tried below code in MySQL:</p>
  <pre><code>SELECT * FROM table 
    WHERE (key='free_shipping' and value='yes') 
    AND (key='price' and value='5')
  </code></pre>
  <p>It doesn't work. I need to get product that is both <strong>free_shipping</strong> is 'yes' AND <strong>price</strong> equal '5' at the same time. How can I create this query properly?</p>
  <p><strong>Table Structure:</strong></p>
  <p><i>contents:</i> (TABLE 1)</p>
  <pre><code>CONTENT_ID   TITLE  DESCRIPTION  DATE
  </code></pre>
  <p><i>content_fields: </i> (TABLE 2)</p>
  <pre><code>FIELD_ID   CONTENT_ID    KEY_NAME    VALUE
  </code></pre>
  <p>Example <i>(Get product that has 1 ID and its shipping is FREE)</i>:</p>
  <pre><code>SELECT *  FROM `contents` as c LEFT JOIN `content_fields` as cf ON  c.content_id = cf.content_id WHERE c.content_id = 1 AND  cf.key_name = 'free_shipping' AND cf.value = 'yes'
  </code></pre>