title: MySQL single statement to merge two tables
body: <p>I'm sure this has been ask/answered already but I don't know how this kind of action is called  and my SQL knowledge is limited.</p>
  
  <p>I'm searching for a single SQL statement to merge two tables:</p>
  
  <p>Table USER:</p>
  
  <pre><code>ID   hash
  =========
  1    abc
  2    def
  3    ghi
  </code></pre>
  
  <p>and the USER_FIELD table:</p>
  
  <pre><code>ID  user_id key        value
  =============================
  1   1       firstname  John
  2   1       lastname   Doe
  3   2       firstname  Justin
  4   2       lastname   Case
  </code></pre>
  
  <p>Now I would like to know how I get this view:</p>
  
  <pre><code>ID  hash  firstname   lastname
  ================================
  1   abc   John        Doe
  </code></pre>
  
  <p>So if I add an addtional entry in the USER_FIELD table with a key "email" I get a new column in the last result</p>
  
  <p>Is this even possible just in MySQL or do I have to go and alter the result in PHP?</p>
  
  <p>Is this even a good DB design or should I drop this an go with a different (which one?)</p>