title: MySQL get row (out of duplicates) with biggest difference between columns
body: <p>I heve the following two tables in MySQL.</p>
  <p><strong>Items</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>code</th>
  <th>value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>6</td>
  </tr>
  <tr>
  <td>2</td>
  <td>8</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>Locations</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>code</th>
  <th>min</th>
  <th>max</th>
  <th>location</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>5</td>
  <td>8</td>
  <td>loc1</td>
  </tr>
  <tr>
  <td>1</td>
  <td>4</td>
  <td>9</td>
  <td>loc2</td>
  </tr>
  <tr>
  <td>2</td>
  <td>6</td>
  <td>10</td>
  <td>loc3</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I want to get the location for each <code>code</code> in <code>Items</code>, where there is the biggest difference between <code>min</code> and <code>max</code>. For <code>code=1</code>, there are two locations assigned, <code>loc1</code> and <code>loc2</code>, but the correct one is <code>loc2</code> because <code>9-4</code> is bigger than <code>8-5</code>.</p>
  <p>The <strong>output</strong> would be</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>code</th>
  <th>value</th>
  <th>location</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>6</td>
  <td>loc2</td>
  </tr>
  <tr>
  <td>2</td>
  <td>8</td>
  <td>loc3</td>
  </tr>
  </tbody>
  </table>
  </div>