title: Extension to my MySQL query. Need to compare values from different row and column
body: <p>This is my table:</p>
  
  <p><img src="https://i.stack.imgur.com/9Bdkc.jpg" alt="enter image description here"></p>
  
  <p>I want to select Code and Number from it and this is visualization of my query:</p>
  
  <p><img src="https://i.stack.imgur.com/uidEe.jpg" alt="enter image description here"></p>
  
  <p>And this is query:</p>
  
  <pre><code>SELECT Code,Number,(1894 - Limit1) AS spread1,(Limit2 - 1894) AS spread2 
  FROM MyTable WHERE Name="John" AND 600&gt;=L1 AND 600&lt;=L2 
  AND 1894&gt;=Limit1 AND 1894&lt;=Limit2
  </code></pre>
  
  <p>As noted in picture this query returns two values and I need just one. So I should compare <strong>spread2</strong> from <strong>row1</strong> with <strong>spread1</strong> from <strong>row2</strong> and take Code and Number of bigger spread and in this case it's <code>spread2</code>. </p>
  
  <p>Why am I comparing <strong>spread2</strong> from row1 and <strong>spread1</strong> from row2 is because they are overlapping their selves. So, I'm comparing spreads within that overlap:</p>
  
  <p><img src="https://i.stack.imgur.com/c3bYG.jpg" alt="enter image description here"> </p>
  
  <p>With my query from above I can get <strong>only one or two rows as a result, never more</strong>. Why? Because table is created that way. If one row appears as a result I won't be needed any comparison, what means that I have single Code and Number.</p>
  
  <p>So, in bottom line, I need extension to my query to do the thing mentioned above.</p>
  
  <p>What I've tried is to add:</p>
  
  <pre><code>ORDER BY (spread2,spread1) DESC LIMIT 1
  </code></pre>
  
  <p>and I'm sure that it does not comparing values as I want rather vales from the same row.</p>