title: MySQL query to get post_id and feature image URL
body: <p>WordPress considers both a post and the post's featured image as two separate posts, which seems to make it impossible to create a SELECT query putting the post and post's image URL into the same row, like this:</p>
  
  <pre><code>post_id  imageURL
  100      [URL]
  </code></pre>
  
  <p>How do you merge two rows in a MySQL table which have no column with a common value? The value in one column is associated with the value in a different column.</p>
  
  <pre><code>meta_id   post_id    meta_key          meta_value  
  100       250        _thumbnail_id     101
  101       255       _wp_attached_file  [URL]
  </code></pre>
  
  <p>...to get a result like this</p>
  
  <pre><code>post_id  imageURL
  100      [URL]
  </code></pre>
  
  <p>WordPress seems to have changed it database structure since this question was answered on this site.</p>
  
  <p>I am trying to understand the principle in MySQL of taking the value from one row and showing it in another row, when "<code>Group by</code>" is not available.</p>
  
  <p>Many hours later of watching videos, trial and error, reading answers here, this query gets me only half-way to solving it, but either the Post ID or the Image URL are always missing. I cannot merge two rows to unite the Post with its image URL.</p>
  
  <pre><code>SELECT * FROM `wp_postmeta`
  INNER JOIN wp_posts on wp_posts.id = wp_postmeta.post_id
  WHERE wp_postmeta.meta_key = "_wp_attached_file"
  ORDER BY `wp_postmeta`.`post_id` DESC
  </code></pre>
  
  <p>Please help. There may be a simple bit of syntax to achieve this, which I am missing. The query is coming in via the WP API, so using raw SQL queries, not the functions available inside WordPress.</p>