title: How do I SELECT a "fake" column/value based on joined table values?
body: <p><strong>Short Version:</strong></p>
  
  <p>I need to customize the result of a query, using one value as the column name, and another value as the column's value. It also needs to be automatic (not hard coded, hundreds of possible "meta keys").</p>
  
  <p><strong>Long Version:</strong></p>
  
  <p>I'm using Wordpress's "user meta" structure, where a single user has a user ID, and another table contains "meta-data" which is related to the user.</p>
  
  <p>This meta data is arbitrary, and only has four columns: </p>
  
  <p><code>meta_id</code>, <code>post_id</code>, <code>meta_key</code>, <code>meta_value</code>.</p>
  
  <p>I would like to do an SQL query for a certain user, and format the results so that all of the metadata is formatted as if they were rows, where the <code>meta_key</code> is a column name, and <code>meta_value</code> is the value for the column.</p>
  
  <hr>
  
  <p><strong>Example database:</strong></p>
  
  <pre><code>-- wp_users
  * ID    | username | email
  35      | radgh    | radgh@example.org
  
  -- wp_usermeta
  * meta_id | user_id | meta_key   | meta_value
  1         | 35      | first-name | Radley
  2         | 35      | last-name  | Sustaire
  3         | 35      | newsletter | on
  </code></pre>
  
  <p><strong>My Query</strong> (I need the (???) portion figured out, which would generate the meta key/value pairs as fake columns)</p>
  
  <pre><code> SELECT 
      `users`.ID as 'user_id',
      `users`.username as 'username',
      `users`.email as 'email',
      (???)
  
   FROM `wp_users` `users`
       INNER JOIN `wp_usermeta` `meta`
       ON `users`.ID = `meta`.user_id
  
   WHERE `wp_users`.ID = 35
  </code></pre>
  
  <p><strong>Desired Outcome:</strong></p>
  
  <pre><code>* user_id | username | email             | first-name | last-name | newsletter
  35        | radgh    | radgh@example.org | Radley     | Sustaire  | on
  </code></pre>
  
  <p>In this <a href="https://stackoverflow.com/questions/10730873/wordpress-users-and-usermeta-joining-multiple-rows-in-one-table-to-one-row-in?rq=1">similar question</a> the selected answer uses hard coded fields. I would like to do this automatically. :)</p>