title: Combine 2 SQL queries in order to avoid foreach loop
body: <p>I want to query a <a href="/questions/tagged/wordpress" class="post-tag" title="show questions tagged &#39;wordpress&#39;" rel="tag">wordpress</a> database in order to get all the desired posts alongside with their images. I have managed to do it with 2 different queries. The first one, brings all the posts alongside with the desired fields and the second one, runs in a foreach loop in order to get the image for each post. My problem is that this takes a really long time and i want to avoid id. I need a solution in order to avoid the <code>foreach</code> loop in the second query and merge it into the first.</p>
  
  <p><strong>Query 1</strong></p>
  
  <pre><code>"SELECT * FROM wp_posts";
  </code></pre>
  
  <p>And foreach returned posts.ID</p>
  
  <p><strong>Query 2</strong></p>
  
  <pre><code>"SELECT wp_posts.guid IN (Select wp_postmeta.meta_value from wp_postmeta where wp_postmeta.meta_key = '_thumbnail_id' AND wp_postmeta.post_id = ('the returned post id foreach of ID output of the first query')"
  </code></pre>