title: Select rows as columns for wordpress post meta
body: <p>WordPress's <code>wp_postmeta</code> table has all the additional fields for a post but they are in rows so it's easy to add more.</p>
  
  <p>However, now I want to query for all the fields of all the posts lets say, I obviously want those fields in a column and not a row.</p>
  
  <p>This is my query that I am running</p>
  
  <pre><code>SELECT p.post_title, 
         m.meta_value, 
         m.meta_key 
  FROM   wp_posts p 
         JOIN wp_postmeta m 
           ON p.id = m.post_id 
  WHERE  p.id = 72697; 
  </code></pre>
  
  <p>This will give me all the meta_values and their respective meta keys as columns. But I need the meta keys values as columns and meta values as rows</p>
  
  <p>For example a <code>meta_key</code> could be <code>additional_description</code> and it's value could be <code>What's up</code></p>
  
  <p>So I need something like this </p>
  
  <pre><code>SELECT p.post_title, additional_description
  FROM   wp_posts p 
         JOIN wp_postmeta m 
           ON p.id = m.post_id 
  WHERE  p.id = 72697; 
  </code></pre>
  
  <p>I need it as a column. I also need all of the posts and not a specific one, but whenever I remove the <code>where</code> it just doesn't query (I have lots of posts, that could be an issue).</p>
  
  <p>Here is some sample data and how I want the results to show up
  wp_postmeta table</p>
  
  <pre><code>meta_key    post_id     meta_key    meta_value
  1       5       total_related   5
  2       5       updated     0
  3       5       cricket     1
  4       8       total_related   8
  5       8       updated     1
  6       8       cricket     0
  
  
  
  wp_post table
  
  id  post_title      other things I dont care about
  5   This is awesome
  8   This is more awesome
  </code></pre>
  
  <p>wp_post id is related to post_id on wp_postmeta table</p>
  
  <p>Result wanted</p>
  
  <pre><code>post_title      total_related   updated     cricket
  This is awesome     5       0       1
  This is more awesome    8       1       0   
  </code></pre>