title: I want to get pivot result based on my two tables
body: <p>Example Data:</p>
  <p>Table: user_field_mapping</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>user_id</th>
  <th>field_id</th>
  <th>field_value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>11</td>
  <td>a</td>
  </tr>
  <tr>
  <td>1</td>
  <td>12</td>
  <td>b</td>
  </tr>
  <tr>
  <td>1</td>
  <td>13</td>
  <td>c</td>
  </tr>
  <tr>
  <td>2</td>
  <td>11</td>
  <td>x</td>
  </tr>
  <tr>
  <td>2</td>
  <td>12</td>
  <td>y</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Table: field_master</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>field_id</th>
  <th>field_name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>11</td>
  <td>fieldnamefor11</td>
  </tr>
  <tr>
  <td>12</td>
  <td>fieldnamefor12</td>
  </tr>
  <tr>
  <td>13</td>
  <td>fieldnamefor13</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Required Result</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>user_id</th>
  <th>fieldnamefor11</th>
  <th>fieldnamefor12</th>
  <th>fieldnamefor13</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>a</td>
  <td>b</td>
  <td>c</td>
  </tr>
  <tr>
  <td>2</td>
  <td>x</td>
  <td>y</td>
  <td>null</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>this is what I tried...</p>
  <pre><code>SELECT d.user_id
       , d.value &quot;fieldnamefor11&quot; 
    FROM user_field_mapping d 
    LEFT 
    JOIN field_master f1 
      ON f1.fieldid=d.field_id 
     AND f1.name = 'fieldnamefor11' 
    LEFT 
    JOIN field_master f2 
      ON f2.id=d.field_id 
     AND f2.name = 'fieldnamefor12' 
   order 
      by user_id
       , field_id 
  </code></pre>