title: MySQL: Subquery to get value based on another value of same column
body: <p>I'm querying the WordPress <a href="https://codex.wordpress.org/Database_Description#Table:_wp_postmeta" rel="nofollow">wp_postmeta table</a> for the lowest <code>meta_value</code> of rows with the meta_key <code>item_thickness</code>:</p>
  
  <p><code>SELECT min(cast(meta_value as unsigned)) FROM wp_postmeta WHERE meta_key='item_thickness'</code></p>
  
  <p>This works great.</p>
  
  <p><strong>Question</strong>: How would I extend this query to select the same lowest <code>item_thickness</code> from rows with the same <code>post_id</code> and with <code>meta_key='item_status'</code> and <code>meta_value='Raw'</code></p>
  
  <p>The <code>post_id</code> forms the relationship between these rows but I don't know how to do a JOIN on the same table or the proper syntax for a sub-query</p>
  
  <p>This is my latest (failing) attempt at the query:</p>
  
  <pre><code>SELECT * 
  FROM wp_postmeta 
  JOIN ( 
    SELECT min(cast(meta_value as unsigned)), post_id FROM wp_postmeta WHERE meta_key='item_thickness'
  ) b 
  ON wp_postmeta.post_id=b.post_id
  </code></pre>