SQL - Retrieve Associated Primary Key and Value of MAX(value) of Query
<p>I have an SQL problem in regards to selecting a max value in a table/query. I am trying to return the maximum value returned from an aggregate expression as well as the associated primary key of the tuple. </p>

<p>I am able to return 1 tuple displaying only the maximum value when I only include the aggregate function in the select statement but I am unable to return just 1 tuple with BOTH the primary key and the max value of the aggregate expression. </p>

<p>Here is an example of my query:</p>

<pre><code>SELECT id, MAX(SQRT((POWER((x-(-28)),2) + POWER((y-(151)),2)))) as distance
FROM table
GROUP BY id;
</code></pre>

<p>As you would expect this returns all the id's and the associated value from the function. It doesn't return just 1 tuple with the maximum value and the associated id.</p>

<p>What can I do to fix this?</p>