title: Export WordPress Posts and Meta Information in CSV format using SQL Query
body: <p><em>Apologies, this is a <a href="https://wordpress.stackexchange.com/questions/67798/export-wordpress-posts-and-meta-information-in-csv-format">duplicate of entry of this post</a> but I found I'm not getting the right answer there and not sure how to ask to move it over to SO?</em></p>
  
  <p>I need to export all WordPress Posts and related Meta information using an SQL query in CSV format. I've managed to export just the Posts but realised that the Meta information is in another table.</p>
  
  <p>Could someone please tell me how I would go about doing this please?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT: I have already tried a number of plugins, none of which have worked for this specific scenario. I really do need to work on the query itself. Thanks</strong></p>
  
  <p><strong>EDIT: The final outcome of the CSV file should look something like this. On one row, these are the columns that I will end up with. (I will delete the additional columns in CSV, I'm just giving a shortened version here)</strong></p>
  
  <pre><code>post_content | post_title | **meta_key** | *meta_value* | **meta_key** | *meta_value* | **meta_key** | *meta_value* | **meta_key** | *meta_value* | **meta_key** | *meta_value* 
  </code></pre>
  
  <p>So one post per row with the meta information in the same row.</p>
  
  <p><strong>EDIT: With the S-ha-dum, I've managed to get some way, but I have about 12 meta_value > meta_key values to pull out of the DB so I need help to write the rest of the query please</strong></p>
  
  <pre><code>SELECT *,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Publisher' AND wp_postmeta.post_id = wp_posts.ID) as Publisher FROM wp_posts
  </code></pre>