title: MySQL and asp select highest row in area
body: <p>I have an MySQL table with 3 fields per entry. x and y are primary keys and one value. I want to select the highest row in a given area.</p>
  
  <p>As an example:
  The table looks like this:<br>
  <a href="https://i.stack.imgur.com/ph6Oz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ph6Oz.jpg" alt=""></a></p>
  
  <p>I want to make a request to get the row with the highest entry with x >=2 and x &lt;4 and y >=1 and y &lt;= 3. In this example this would be the row with x = 2, y = 3 and value = 0,6.</p>
  
  <p>Currently, the code in my .asp file looks like this:</p>
  
  <pre><code>if reqType="getDBMaxValue" then
    resp="[ "
    delim=""
    'sSQL="SELECT MAX(value) AS value FROM "&amp;tableName&amp;" WHERE x &gt;= "&amp;xStart&amp;" AND x &lt;= "&amp;xEnd&amp;" AND y &gt;= "&amp;yStart&amp;" AND y &lt;= "&amp;yEnd
    sSQL="SELECT MAX(value) AS value FROM "&amp;tableName&amp;" WHERE x &gt;= "&amp;xStart&amp;" AND x &lt;= "&amp;xEnd&amp;" AND y &gt;= "&amp;yStart&amp;" AND y &lt;= "&amp;yEnd
    set rs=Conn.Execute(sSQL)
    do until rs.EOF
      obj="{ " &amp; chr(34) &amp; "value" &amp; chr(34) &amp; ": " &amp; chr(34) &amp; rs.Fields("value") &amp; chr(34)
      obj=obj &amp; "} "
      resp=resp &amp; delim &amp; obj
      delim=" , "
    rs.MoveNext
    loop
    resp=resp &amp; " ]"
  
    rs.Close
    response.ContentType="application/json"
    Response.Write(resp)
  end if
  </code></pre>
  
  <p>This returns the correct value, but I don't get the x and y.</p>
  
  <p>With this code:</p>
  
  <pre><code>if reqType="getDBvalues" then
    resp="[ "
    delim=""
    sSQL="SELECT * FROM "&amp;tableName&amp;" WHERE x &gt;= "&amp;xStart&amp;" AND x &lt;= "&amp;xEnd&amp;" AND y &gt;= "&amp;yStart&amp;" AND y &lt;= "&amp;yEnd
    set rs=Conn.Execute(sSQL)
    do until rs.EOF
      obj="{ " &amp; chr(34) &amp; "x" &amp; chr(34) &amp; ": " &amp; chr(34) &amp; rs.Fields("x") &amp; chr(34)
      obj=obj &amp; ", " &amp; chr(34) &amp; "y" &amp; chr(34) &amp; ": " &amp; chr(34) &amp; rs.Fields("y") &amp; chr(34)
      obj=obj &amp; ", " &amp; chr(34) &amp; "value" &amp; chr(34) &amp; ": " &amp; chr(34) &amp; rs.Fields("value") &amp; chr(34)
      obj=obj &amp; "} "
      resp=resp &amp; delim &amp; obj
      delim=" , "
    rs.MoveNext
    loop
    resp=resp &amp; " ]"
  
    rs.Close
    response.ContentType="application/json"
    Response.Write(resp)
  end if
  </code></pre>
  
  <p>I receive the whole row (or rows).</p>
  
  <p>Does someone know how I can write down the MySQL statement to get the row with the max value?</p>